File: 06can.t

package info (click to toggle)
libhash-asobject-perl 0.13-4
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 124 kB
  • sloc: perl: 239; makefile: 2
file content (21 lines) | stat: -rw-r--r-- 641 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
use strict;
use warnings;

use Test::More tests => 8;

use_ok( 'Hash::AsObject' );

my $o = Hash::AsObject->new({ 'a' => 42 });

my $a = $o->can('a');
my $b = $o->can('b');

is( ref($a), 'CODE', 'can returns a code ref if the key exists' );
is( ref($b), 'CODE', 'can returns a code ref if the key doesn\'t exist' );

is( $a->($o),     42, 'use can to invoke getter'        );
is( $a->($o, 99), 99, 'use can to invoke setter'        );
is( $a->($o, 99), 99, 'setter invoked using can worked' );

is( $b->($o, 23), 23, 'use can to invoke setter (key doesn\'t exist)' );
is( $b->($o),     23, 'use can to invoke getter'                      );