Skip to content

Commit

Permalink
various
Browse files Browse the repository at this point in the history
  • Loading branch information
jonswar committed Jun 28, 2010
1 parent 04a30bf commit c45c597
Show file tree
Hide file tree
Showing 5 changed files with 807 additions and 18 deletions.
3 changes: 0 additions & 3 deletions Makefile.PL
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@ author 'Jonathan Swartz <swartz@pobox.com>';
perl_version '5.006';

build_requires 'Test::Class' => 0;
build_requires 'Test::Most' => 0;

# requires 'List::MoreUtils' => '0.13';

license 'perl';

Expand Down
126 changes: 111 additions & 15 deletions lib/Poet.pm
Original file line number Diff line number Diff line change
@@ -1,9 +1,61 @@
package Poet;
use 5.006;
use Poet::Environment;
use strict;
use warnings;

our $VERSION = '0.01';
our $VERSION = '6.0.0';

sub import {
my $pkg = shift;
$pkg->export_to_level( 1, undef, @_ );
}

sub export_to_level {
my ( $pkg, $level, $ignore, @params ) = @_;

# Import requested globals into caller.
#
my @vars = grep { /^\$/ } @params;
my @valid_import_params = qw($cache $conf $env $log);
if (@vars) {
my ($caller) = caller($level);

foreach my $var (@vars) {
my $value;
if ( $var eq '$conf' ) {
$value = Poet::Environment->get_environment()->conf()
or die "configuration has not been initialized!";
}
elsif ( $var eq '$env' ) {
$value = Poet::Environment->get_environment()
or die "environment has not been initialized!";
}
elsif ( $var eq '$log' ) {
$value = Log::Any->get_logger( category => $caller );
}
else {
die sprintf(
"unknown import parameter '$var' passed to Poet: valid import parameters are %s",
join( ", ", map { "'$_'" } @valid_import_params ) );
}
my $no_sigil_var = substr( $var, 1 );
no strict 'refs';
*{"$caller\::$no_sigil_var"} = \$value;
}
}
}

sub initialize_environment {
my ( $class, $root_dir ) = @_;
Poet::Environment->initialize_current_environment($root_dir);
}

sub initialize_environment_if_needed {
my $class = shift;
if ( !Poet::Environment->get_environment() ) {
Poet::Environment->initialize_current_environment(@_);
}
}

1;

Expand All @@ -13,33 +65,77 @@ __END__
=head1 NAME
Poet -- Lightweight application environment
Poet -- A flexible application environment
=head1 SYNOPSIS
use Poet;
# In a module...
use Poet qw($conf $env $log);
=head1 DESCRIPTION
Poet provides
Poet provides a flexible environment for a web or standalone application. It
gives you
=head1 AUTHOR
=over
Jonathan Swartz
=item *
A standard root directory with conf, lib, bin, etc., autodetected from any
script inside the environment
=item *
A multi-file configuration layout with knowledge of different application
"layers"
=item *
Easy one-line access to environment, configuration, caching and logging objects
=back
=for readme stop
=head1 IMPORTS
The sole purpose of 'use Poet' is to import standard Poet variables into the
current package. You can import the same variables from 'use Poet::Script' when
initializing a script.
The variables are:
=over
=item $conf
The global configuration object provided by L<Poet::Conf|Poet::Conf>.
=item $env
The global environment object provided by
L<Poet::Environment|Poet::Environment>.
=item $log
The logger for the current package, provided by L<Log::Any|Log::Any>.
=back
=head1 SEE ALSO
L<Some::Module>
Poet::Script
=head1 COPYRIGHT & LICENSE
=for readme continue
Copyright (C) 2009 Jonathan Swartz.
=head1 ACKNOWLEDGEMENTS
Poet is provided "as is" and without any express or implied warranties,
including, without limitation, the implied warranties of merchantibility and
fitness for a particular purpose.
Poet was originally designed and developed for the Digital Media group of the
Hearst Corporation, a diversified media company based in New York City. Many
thanks to Hearst management for agreeing to this open source release.
This program is free software; you can redistribute it and/or modify it under
the same terms as Perl itself.
=head1 AUTHOR
Jonathan Swartz
=cut
Loading

0 comments on commit c45c597

Please sign in to comment.