File Coverage

blib/lib/Exception/Delayed.pm
Criterion Covered Total %
statement 26 28 92.8
branch 8 10 80.0
condition n/a
subroutine 5 5 100.0
pod 3 3 100.0
total 42 46 91.3


line stmt bran cond sub pod time code
1             package Exception::Delayed;
2              
3             # ABSTRACT: Execute code and throw exceptions later
4              
5 3     3   40494 use strict;
  3         4  
  3         96  
6 3     3   10 use warnings;
  3         3  
  3         549  
7              
8             our $VERSION = '0.001'; # VERSION
9              
10             sub wantscalar {
11 2     2 1 33 my ( $class, $code, @args ) = @_;
12 2         3 my $RV;
13 2         3 eval { $RV = scalar $code->(@args); };
  2         6  
14 2 100       20 if ($@) {
15 1         4 return bless { error => $@ } => $class;
16             }
17             else {
18 1         6 return bless { result => \$RV } => $class;
19             }
20             }
21              
22             sub wantlist {
23 1     1 1 11 my ( $class, $code, @args ) = @_;
24 1         1 my @RV;
25 1         2 eval { @RV = $code->(@args); };
  1         3  
26 1 50       8 if ($@) {
27 0         0 return bless { error => $@ } => $class;
28             }
29             else {
30 1         5 return bless { result => \@RV } => $class;
31             }
32             }
33              
34             sub result {
35 3     3 1 2003 my ($self) = @_;
36 3 100       22 if ( exists $self->{error} ) {
37 1         6 die $self->{error};
38             }
39             else {
40 2         6 my $result = delete $self->{result};
41 2 100       8 if ( ref $result eq 'ARRAY' ) {
    50          
42 1         3 return @$result;
43             }
44             elsif ( ref $result eq 'SCALAR' ) {
45 1         3 return $$result;
46             }
47             else {
48 0           return;
49             }
50             }
51             }
52              
53             1;
54              
55             __END__