-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,10 +4,12 @@ use 5.010; | |
use strict; | ||
use warnings; | ||
|
||
require B; | ||
This comment has been minimized.
Sorry, something went wrong. |
||
|
||
# Can't use sigantures here, Signatures needs CODE. | ||
|
||
use Hash::FieldHash qw(fieldhashes); | ||
fieldhashes \my(%Signatures); | ||
fieldhashes \my ( %Signatures, %Endline ); | ||
|
||
sub __set_signature { | ||
$Signatures{$_[0]} = $_[1]; | ||
|
@@ -17,4 +19,24 @@ sub signature { | |
return $Signatures{$_[0]}; | ||
} | ||
|
||
sub start_line { | ||
return B::svref_2object( $_[0] )->START->line; | ||
} | ||
|
||
sub __set_end_line { | ||
return $Endline{$_[0]} = $_[1]; | ||
} | ||
|
||
sub end_line { | ||
return $Endline{$_[0]}; | ||
} | ||
|
||
sub original_name { | ||
return B::svref_2object( $_[0] )->GV->NAME; | ||
} | ||
|
||
sub original_package { | ||
return B::svref_2object( $_[0] )->GV->STASH->NAME; | ||
} | ||
This comment has been minimized.
Sorry, something went wrong.
schwern
Contributor
|
||
|
||
1; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
#!/usr/bin/perl | ||
use strict; | ||
use warnings; | ||
|
||
use perl5i::latest; | ||
use Test::More; | ||
|
||
# Note, do not let the line number for these subs change! | ||
This comment has been minimized.
Sorry, something went wrong.
schwern
Contributor
|
||
sub foo { 1 } | ||
my $foo2 = sub { 1 }; | ||
method a_method { | ||
print "1"; | ||
print "2"; | ||
} | ||
func a_func { | ||
print "1"; | ||
print "2"; | ||
} | ||
|
||
my $code = __PACKAGE__->can('foo'); | ||
|
||
is( $code->original_name, 'foo', "Can get original name" ); | ||
is( $code->original_package, 'main', "Can get original package" ); | ||
is( $code->start_line, 9, "Can get start line" ); | ||
is( $code->end_line, undef, "No end line set" ); | ||
This comment has been minimized.
Sorry, something went wrong.
schwern
Contributor
|
||
|
||
$code = $foo2; | ||
is( $code->original_name, '__ANON__', "Can get original name (has none)" ); | ||
is( $code->original_package, 'main', "Can get original package" ); | ||
is( $code->start_line, 10, "Can get start line" ); | ||
is( $code->end_line, undef, "No end line set" ); | ||
|
||
$code = __PACKAGE__->can('a_method'); | ||
is( $code->original_name, 'a_method', "Can get original name" ); | ||
is( $code->original_package, 'main', "Can get original package" ); | ||
is( $code->start_line, 11, "Can get start line" ); | ||
is( $code->end_line, 14, "Can get end line" ); | ||
|
||
$code = __PACKAGE__->can('a_func'); | ||
is( $code->original_name, 'a_func', "Can get original name" ); | ||
is( $code->original_package, 'main', "Can get original package" ); | ||
is( $code->start_line, 16, "Can get start line (or first statement line)" ); | ||
is( $code->end_line, 18, "Can get end line" ); | ||
|
||
done_testing; |
Load this on demand inside the methods as needed. Otherwise it adds 5-10% to our load time.