1use strict;
2use warnings;
3use lib 't/lib';
4use Test::More;
5use Test::Fatal;
6
7BEGIN { $^P |= 0x210 } # PERLDBf_SUBLINE
8
9use Package::Stash;
10
11my $foo_stash = Package::Stash->new('Foo');
12
13# ----------------------------------------------------------------------
14## test adding a CODE
15
16ok(!defined($Foo::{funk}), '... the &funk slot has not been created yet');
17
18is(exception {
19    $foo_stash->add_symbol('&funk' => sub { "Foo::funk", __LINE__ });
20}, undef, '... created &Foo::funk successfully');
21
22ok(defined($Foo::{funk}), '... the &funk slot was created successfully');
23
24{
25    no strict 'refs';
26    ok(defined &{'Foo::funk'}, '... our &funk exists');
27}
28
29is((Foo->funk())[0], 'Foo::funk', '... got the right value from the function');
30
31my $line = (Foo->funk())[1];
32is $DB::sub{'Foo::funk'}, sprintf( "%s:%d-%d", __FILE__, $line, $line ),
33    '... got the right %DB::sub value for funk default args';
34
35$foo_stash->add_symbol(
36    '&dunk'        => sub { "Foo::dunk" },
37    filename       => "FileName",
38    first_line_num => 100,
39    last_line_num  => 199
40);
41
42is $DB::sub{'Foo::dunk'}, sprintf( "%s:%d-%d", "FileName", 100, 199 ),
43    '... got the right %DB::sub value for dunk with specified args';
44
45done_testing;
46