diff options
author | Jesse Luehrs <doy@tozt.net> | 2010-05-31 12:28:19 -0500 |
---|---|---|
committer | Jesse Luehrs <doy@tozt.net> | 2010-05-31 12:28:19 -0500 |
commit | 640de3695dc6b9a77793ee3c1c03c5f062906295 (patch) | |
tree | f8c29cfd27a9be94090c6f5d151f39e02628ef13 | |
parent | 4ada57e0b39192a0002ff703b7af0f3bd99003fa (diff) | |
download | package-stash-xs-640de3695dc6b9a77793ee3c1c03c5f062906295.tar.gz package-stash-xs-640de3695dc6b9a77793ee3c1c03c5f062906295.zip |
named args for add_package_symbol
-rw-r--r-- | lib/Package/Stash.pm | 13 | ||||
-rw-r--r-- | t/006-addsub.t | 7 |
2 files changed, 13 insertions, 7 deletions
diff --git a/lib/Package/Stash.pm b/lib/Package/Stash.pm index d3c3071..d632c37 100644 --- a/lib/Package/Stash.pm +++ b/lib/Package/Stash.pm @@ -136,7 +136,7 @@ sub _valid_for_type { } sub add_package_symbol { - my ($self, $variable, $initial_value) = @_; # extra args unpacked below + my ($self, $variable, $initial_value, %opts) = @_; my ($name, $sigil, $type) = ref $variable eq 'HASH' ? @{$variable}{qw[name sigil type]} @@ -150,15 +150,16 @@ sub add_package_symbol { # cheap fail-fast check for PERLDBf_SUBLINE and '&' if ($^P and $^P & 0x10 && $sigil eq '&') { - my (undef, undef, undef, $filename, $firstlinenum, $lastlinenum) = @_; + my $filename = $opts{filename}; + my $first_line_num = $opts{first_line_num}; - (undef, $filename, $firstlinenum) = caller + (undef, $filename, $first_line_num) = caller if not defined $filename; - $lastlinenum = $firstlinenum ||= 0 - if not defined $lastlinenum; + + my $last_line_num = $opts{last_line_num} || ($first_line_num ||= 0); # http://perldoc.perl.org/perldebguts.html#Debugger-Internals - $DB::sub{$pkg . '::' . $name} = "$filename:$firstlinenum-$lastlinenum"; + $DB::sub{$pkg . '::' . $name} = "$filename:$first_line_num-$last_line_num"; } } diff --git a/t/006-addsub.t b/t/006-addsub.t index b5a5822..3c0dfc8 100644 --- a/t/006-addsub.t +++ b/t/006-addsub.t @@ -32,7 +32,12 @@ my $line = (Foo->funk())[1]; is $DB::sub{'Foo::funk'}, sprintf "%s:%d-%d", __FILE__, $line, $line, '... got the right %DB::sub value for funk default args'; -$foo_stash->add_package_symbol('&dunk' => sub { "Foo::dunk" }, "FileName", 100, 199); +$foo_stash->add_package_symbol( + '&dunk' => sub { "Foo::dunk" }, + filename => "FileName", + first_line_num => 100, + last_line_num => 199 +); is $DB::sub{'Foo::dunk'}, sprintf "%s:%d-%d", "FileName", 100, 199, '... got the right %DB::sub value for dunk with specified args'; |