From 04061a7131ade4c9411380e6b2b61b1547751c38 Mon Sep 17 00:00:00 2001 From: dakkar Date: Tue, 27 Sep 2011 22:09:55 +0100 Subject: "use" seems to work --- dist.ini | 3 +++ lib/Dist/Zilla/Plugin/Boilerplate.pm | 20 ++++++++++++++++++-- t/lib/TestModule.pm | 4 ++++ 3 files changed, 25 insertions(+), 2 deletions(-) create mode 100644 t/lib/TestModule.pm diff --git a/dist.ini b/dist.ini index 798db7f..862674b 100644 --- a/dist.ini +++ b/dist.ini @@ -7,3 +7,6 @@ copyright_year = 2011 version = 0.001 [@Basic] + +[Boilerplate / foo] +code = our $foo = 1; diff --git a/lib/Dist/Zilla/Plugin/Boilerplate.pm b/lib/Dist/Zilla/Plugin/Boilerplate.pm index 87e84a8..0a0d25e 100644 --- a/lib/Dist/Zilla/Plugin/Boilerplate.pm +++ b/lib/Dist/Zilla/Plugin/Boilerplate.pm @@ -4,10 +4,13 @@ use Moose; use namespace::autoclean; use PPI; use Moose::Autobox 0.09; +use Path::Class; #use This::Is::A::Test 'foo','bar'; #use This::Is::A::Test ('foo','bar'); #use This::Is::A::Test qw(foo bar); +# ABSTRACT: foo + with( 'Dist::Zilla::Role::FileMunger', 'Dist::Zilla::Role::FileFinderUser' => { @@ -30,7 +33,10 @@ has _parsed_code => ( ); sub _build_parsed_code { my ($self) = @_; - PPI::Document->new($self->code); + +warn "parsing ".$self->code."\n"; + + PPI::Document->new(\$self->code); } sub import { @@ -59,12 +65,22 @@ sub import { 1; } +sub _find_dzil_root { + my ($self,$filename) = @_; + + my $d = file($filename)->parent; + while ($d && ! glob($d->file('dist.*'))) { $d=$d->parent } + return $d; +} + sub eval_in { my ($self,$package) = @_; my $code = $self->code;my $name = $self->plugin_name; + my $str = "{package $package;$code;1}"; + warn "evaling $str\n"; local $@; - eval "package $package;$code;1" + eval $str or $self->log_error("Couldn't eval code for boilerplate $name into $package: $@"); } diff --git a/t/lib/TestModule.pm b/t/lib/TestModule.pm new file mode 100644 index 0000000..ebf7dcd --- /dev/null +++ b/t/lib/TestModule.pm @@ -0,0 +1,4 @@ +package TestModule; +use Dist::Zilla::Plugin::Boilerplate 'foo'; + +1; -- cgit v1.2.3