1
use Contextual::Return;
2
use Test::More 'no_plan';
5
sub foo_with_default_method {
8
bar => sub { 'bar method called' },
9
qr/ba(.)/ => sub { $1 . ' method called' },
10
['qux','dux'] => sub { "$_ method called" },
11
qr/.*/ => sub { 'DEFAULT method called' },
13
DEFAULT { 'DEFAULT value' }
16
is foo_with_default_method()->bar, 'bar method called', 'bar method';
17
is foo_with_default_method()->baz, 'z method called', 'baz method';
18
is foo_with_default_method()->qux, 'qux method called', 'qux method';
19
is foo_with_default_method()->dux, 'dux method called', 'dux method';
20
is foo_with_default_method()->jax, 'DEFAULT method called', 'DEFAULT method';
21
is foo_with_default_method() , 'DEFAULT value', 'DEFAULT';
24
sub foo_with_method_and_obj {
27
bar => sub { 'bar method called' },
32
DEFAULT { 'DEFAULT value' }
35
is foo_with_method_and_obj()->bar, 'bar method called', 'bar method called';
36
is foo_with_method_and_obj()->baz, 'Bar::baz', 'OBJREF method called';
37
is foo_with_method_and_obj() , 'DEFAULT value', 'DEFAULT value';
44
sub baz { "Bar::baz" }