diff options
author | Tim Bunce <Tim.Bunce@pobox.com> | 2010-05-30 15:24:59 +0100 |
---|---|---|
committer | Tim Bunce <Tim.Bunce@pobox.com> | 2010-05-30 15:24:59 +0100 |
commit | 4ada57e0b39192a0002ff703b7af0f3bd99003fa (patch) | |
tree | 55ebc8501629d2bf7656369c895f85eaaca4b9df /t | |
parent | 18713f832189fda11e472a9357620a05e19f85e0 (diff) | |
download | package-stash-4ada57e0b39192a0002ff703b7af0f3bd99003fa.tar.gz package-stash-4ada57e0b39192a0002ff703b7af0f3bd99003fa.zip |
Extend add_package_symbol to set %DB::sub if appropriate.
Helps NYTProf and debuggers.
Diffstat (limited to 't')
-rw-r--r-- | t/006-addsub.t | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/t/006-addsub.t b/t/006-addsub.t new file mode 100644 index 0000000..b5a5822 --- /dev/null +++ b/t/006-addsub.t @@ -0,0 +1,40 @@ +use strict; +use warnings; + +use Test::More; +use Test::Exception; + +BEGIN { $^P |= 0x210 } # PERLDBf_SUBLINE + +use Package::Stash; + +my $foo_stash = Package::Stash->new('Foo'); + +# ---------------------------------------------------------------------- +## test adding a CODE + +ok(!defined($Foo::{funk}), '... the &funk slot has not been created yet'); + +lives_ok { + $foo_stash->add_package_symbol('&funk' => sub { "Foo::funk", __LINE__ }); +} '... created &Foo::funk successfully'; + +ok(defined($Foo::{funk}), '... the &funk slot was created successfully'); + +{ + no strict 'refs'; + ok(defined &{'Foo::funk'}, '... our &funk exists'); +} + +is((Foo->funk())[0], 'Foo::funk', '... got the right value from the function'); + +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); + +is $DB::sub{'Foo::dunk'}, sprintf "%s:%d-%d", "FileName", 100, 199, + '... got the right %DB::sub value for dunk with specified args'; + +done_testing; |