Data-Object-Try
view release on metacpan or search on metacpan
t/Data_Object_Try.t view on Meta::CPAN
object.
=signature no_finally
no_finally() : Object
=example-1 no_finally
use routines;
my $try = Data::Object::Try->new(
invocant => Example->new,
arguments => [1,2,3]
);
$try->call(fun (@args) {
return $try;
});
$try->finally(fun (@args) {
$try->{'$finally'} = [@args];
});
$try->no_finally;
=cut
=method no_try
The no_try method removes any configured C<try> operation and returns the
object.
=signature no_try
no_try() : Object
=example-1 no_try
use routines;
my $try = Data::Object::Try->new;
$try->call(fun (@args) {
return [@args];
});
$try->no_try;
=cut
=method result
The result method executes the try/catch/default/finally logic and returns
either 1) the return value from the successfully tried operation 2) the return
value from the successfully matched catch condition if an exception was thrown
3) the return value from the default catch condition if an exception was thrown
and no catch condition matched. When invoked, the C<try> and C<finally>
callbacks will received an C<invocant> if one was provided to the constructor,
the default C<arguments> if any were provided to the constructor, and whatever
arguments were passed directly to this method.
=signature result
result(Any @args) : Any
=example-1 result
use routines;
my $try = Data::Object::Try->new;
$try->call(fun (@args) {
return [@args];
});
$try->result;
=example-2 result
use routines;
my $try = Data::Object::Try->new;
$try->call(fun (@args) {
return [@args];
});
$try->result(1..5);
=cut
package main;
my $test = testauto(__FILE__);
my $subs = $test->standard;
$subs->synopsis(fun($tryable) {
ok my $result = $tryable->result;
$result
});
$subs->example(-1, 'call', 'method', fun($tryable) {
ok my $result = $tryable->result;
ok $result->isa('Data::Object::Try');
is_deeply $result->result(1..4), [1..4];
$result
});
$subs->example(-1, 'callback', 'method', fun($tryable) {
ok my $result = $tryable->result;
is ref $result, 'CODE';
is_deeply $result->(1..4), [1..4];
( run in 0.579 second using v1.01-cache-2.11-cpan-39bf76dae61 )