return $attrs;
}
+sub code_for {
+ my ($self, $name) = @_;
+
+ if (defined $name) {
+ my $pkg = $self->get_curstash_name;
+ $name = join( '::', $pkg, $name )
+ unless( $name =~ /::/ );
+ return sub (&) {
+ my $code = shift;
+ # So caller() gets the subroutine name
+ no strict 'refs';
+ *{$name} = subname $name => $code;
+ return;
+ };
+ } else {
+ return sub (&) { shift };
+ }
+}
+
+sub install {
+ my ($self, $name ) = @_;
+
+ $self->shadow( $self->code_for($name) );
+}
+
sub parser {
my $self = shift;
$self->init(@_);
$inject = $self->scope_injector_call() . $inject;
}
$self->inject_if_block($inject, $attrs ? "sub ${attrs} " : '');
- if (defined $name) {
- my $pkg = $self->get_curstash_name;
- $name = join( '::', $pkg, $name )
- unless( $name =~ /::/ );
- $self->shadow( sub (&) {
- my $code = shift;
- # So caller() gets the subroutine name
- no strict 'refs';
- *{$name} = subname $name => $code;
- });
- } else {
- $self->shadow(sub (&) { shift });
- }
+
+ $self->install( $name );
+
+ return;
}
sub parse_proto { }
+#!/usr/bin/perl -w
+
+use strict;
+use Test::More 'no_plan';
+
+my $Have_Devel_BeginLift;
+BEGIN {
+ # setup_for_cv() introduced in 0.001001
+ $Have_Devel_BeginLift = eval q{ use Devel::BeginLift 0.001001; 1 };
+}
+
{
package MethodHandlers;
return $inject;
}
+ sub code_for {
+ my($self, $name) = @_;
+
+ my $code = $self->SUPER::code_for($name);
+
+ if( defined $name and $Have_Devel_BeginLift ) {
+ Devel::BeginLift->setup_for_cv($code);
+ }
+
+ return $code;
+ }
}
my ($test_method1, $test_method2, @test_list);
);
}
+ # Test at_BEGIN
+ SKIP: {
+ ::skip "Need Devel::BeginLift for compile time methods", 1
+ unless $Have_Devel_BeginLift;
+ ::can_ok( "DeclareTest", qw(new foo upgrade) );
+ }
+
method new {
my $class = ref $self || $self;
return bless({ @_ }, $class);
method leftie($left) : method { $self->{left} ||= $left; $self->{left} };
}
-use Test::More 'no_plan';
my $o = DeclareTest->new(attr => "value");