File Coverage

blib/lib/results/wrap.pm
Criterion Covered Total %
statement 22 24 91.6
branch 3 4 75.0
condition 2 3 66.6
subroutine 7 7 100.0
pod 0 1 0.0
total 34 39 87.1


line stmt bran cond sub pod time code
1 1     1   228931 use 5.014;
  1         8  
2 1     1   5 use strict;
  1         1  
  1         19  
3 1     1   4 use warnings;
  1         2  
  1         33  
4              
5 1     1   428 use results ();
  1         2  
  1         111  
6              
7             package results::wrap;
8              
9             our $AUTHORITY = 'cpan:TOBYINK';
10             our $VERSION = '0.005';
11              
12             BEGIN {
13 1 50   1   5 if ( $] ge '5.034' ) {
14 0         0 require experimental;
15 0         0 'experimental'->import( 'try' );
16             }
17             else {
18 1         486 require Syntax::Keyword::Try;
19 1         2427 'Syntax::Keyword::Try'->import;
20             }
21             };
22              
23             sub AUTOLOAD {
24 2     2   6432 my ( $invocant, @args ) = @_;
25 2         18 my ( $method ) = ( our $AUTOLOAD =~ /::(\w+)$/ );
26             try {
27             return results::ok( $invocant->$method( @args ) );
28             }
29 2         7 catch ( $e ) {
30             return results::err( $e );
31             }
32             }
33              
34             sub results::wrap (&) {
35 4 100 66 4 0 79937 if ( @_ == 1 and ref($_[0]) eq 'CODE' ) {
36 2         10 my ( $code ) = @_;
37             try {
38             return results::ok( $code->() );
39             }
40 2         5 catch ( $e ) {
41             return results::err( $e );
42             }
43             }
44             else {
45 2         11 my ( $invocant, $method, @args ) = @_;
46             try {
47             return results::ok( $invocant->$method( @args ) );
48             }
49 2         6 catch ( $e ) {
50             return results::err( $e );
51             }
52             }
53             }
54              
55             1;
56              
57             __END__