Permalink
Browse files

add export_to_class

  • Loading branch information...
1 parent a268359 commit f44e33098f7b1a38cdbbfca806b3d4d7ccedb6f9 @jonswar committed Jun 8, 2012
Showing with 25 additions and 2 deletions.
  1. +25 −2 lib/Poet/Import.pm
View
@@ -21,6 +21,8 @@ method _build_default_tags () {
}
method export_to_level ($level, @params) {
+ my ($caller) = caller($level);
+ $self->export_to_class($caller);
foreach my $param (@params) {
if ( substr( $param, 0, 1 ) eq '$' ) {
$self->export_var_to_level( substr( $param, 1 ), $level + 1 );
@@ -34,6 +36,9 @@ method export_to_level ($level, @params) {
}
}
+method export_to_class ($class) {
+}
+
method export_var_to_level ($var, $level) {
my $provide_method = "provide_var_" . $var;
if ( $self->can($provide_method) ) {
@@ -75,8 +80,7 @@ method provide_var_env ($caller) {
}
method provide_var_log ($caller) {
- require Log::Any;
- Log::Any->get_logger( category => $caller );
+ $self->env->app_class('Log')->get_logger( category => $caller );
}
method provide_var_poet ($caller) {
@@ -219,3 +223,22 @@ Now your scripts and libraries can do
use Poet::Script qw(:hash);
use Poet qw(:hash);
+
+=head2 Other exports
+
+To export other general things to the calling class, you can override
+C<export_to_class>, which takes the calling class as its argument. e.g.
+
+ package MyApp::Import;
+ use Poet::Moose;
+ extends 'Poet::Import';
+
+ before 'export_to_class' => sub {
+ my ($self, $class) = @_;
+ no strict 'refs';
+ %{$class . "::some_name"} = ...;
+ }
+
+=over
+
+=back

0 comments on commit f44e330

Please sign in to comment.