File: inline_object.t

package info (click to toggle)
libplack-perl 0.9989-1%2Bdeb7u1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 1,556 kB
  • sloc: perl: 6,890; python: 6; makefile: 2
file content (21 lines) | stat: -rw-r--r-- 522 bytes parent folder | download | duplicates (10)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
use Test::More;
use Plack::Util;
use Try::Tiny;

my $counter;
my $object = Plack::Util::inline_object(
    method1 => sub { $counter++ },
);

$object->method1;
is $counter, 1, 'method call works';

my $sub = $object->can('method1');
ok $sub, 'can returns true value for method';
try { $sub->($object) };
is $counter, 2, 'can returns sub ref for method';

ok ! try { $object->method2; 1 }, 'croaks if nonexistant method called';
is $object->can('method2'), undef, 'can returns undef for nonexistant method';

done_testing;