1 package MooseX::Antlers::DevelDeclareHandler;
3 use Method::Signatures::Simple ();
5 use B::Hooks::EndOfScope;
10 my $orig_block = Devel::Declare::Context::Simple->can('inject_if_block');
12 *Devel::Declare::Context::Simple::inject_if_block = sub {
14 my $line = $_[0]->get_linestr;
15 $line =~ s/BEGIN {.*?};//;
16 push(@{$fix{PL_compiling->file}}, [ PL_compiling->line, $line ]);
19 my $orig_scope = Devel::Declare::Context::Simple->can('inject_scope');
21 *Devel::Declare::Context::Simple::inject_scope = sub {
25 push(@{$fix{PL_compiling->file}}, [ PL_compiling->line, $self->get_linestr ]);
29 my $orig_install = Devel::Declare::MethodInstaller::Simple->can('install');
31 *Devel::Declare::MethodInstaller::Simple::install = sub {
32 push(@{$names{PL_compiling->file}}, $_[1]);
39 my @self = io($file)->getlines;
40 my @methods = @{$names{$file}};
41 my $method_section = q!
45 my @methods = qw(!.join(' ', @methods).q!);
47 my $name = shift(@methods);
48 *$name = Sub::Name::subname $name => $_[0];
51 use MooseX::Antlers::StealImport
52 'Method::Signatures::Simple' => {
56 foreach my $f (@{$fix{$file}}) {
57 my ($line, $linestr) = @$f;
58 $self[$line-1] = $linestr;
60 return join("", $method_section, @self);