| 1 | package Exception::Delayed; | ||||||||||||||
| 2 | |||||||||||||||
| 3 | # ABSTRACT: Execute code and throw exceptions later | ||||||||||||||
| 4 | |||||||||||||||
| 5 | 4 | ▶ | use strict; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 6 | 4 | ▶ | use warnings; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 7 | |||||||||||||||
| 8 | 4 | our $VERSION = '0.002'; # VERSION | |||||||||||||
| 9 | |||||||||||||||
| 10 | 3 | ▶ | sub wantscalar { | ||||||||||||
|
Subroutine
wantscalar: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||
| 11 | 3 | my ( $class, $code, @args ) = @_; | |||||||||||||
| 12 | 3 | my $RV; | |||||||||||||
| 13 | 3 | eval { $RV = scalar $code->(@args); }; | |||||||||||||
| 14 | 3 | ▶ | if ($@) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 15 | 1 | return bless { error => $@ } => $class; | |||||||||||||
| 16 | } | ||||||||||||||
| 17 | else { | ||||||||||||||
| 18 | 2 | return bless { result => \$RV } => $class; | |||||||||||||
| 19 | } | ||||||||||||||
| 20 | } | ||||||||||||||
| 21 | |||||||||||||||
| 22 | 2 | ▶ | sub wantlist { | ||||||||||||
|
Subroutine
wantlist: called CC=2 SCAR=7.1
Pod
documented
| |||||||||||||||
| 23 | 2 | my ( $class, $code, @args ) = @_; | |||||||||||||
| 24 | 2 | my @RV; | |||||||||||||
| 25 | 2 | eval { @RV = $code->(@args); }; | |||||||||||||
| 26 | 2 | ▶ | if ($@) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 27 | 0 | return bless { error => $@ } => $class; | |||||||||||||
| 28 | } | ||||||||||||||
| 29 | else { | ||||||||||||||
| 30 | 2 | return bless { result => \@RV } => $class; | |||||||||||||
| 31 | } | ||||||||||||||
| 32 | } | ||||||||||||||
| 33 | |||||||||||||||
| 34 | 2 | ▶ | sub wantany { | ||||||||||||
|
Subroutine
wantany: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||
| 35 | 2 | my ( $class, $wantarray, $code, @args ) = @_; | |||||||||||||
| 36 | 2 | ▶ | if ($wantarray) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 37 | 1 | return $class->wantlist( $code, @args ); | |||||||||||||
| 38 | } | ||||||||||||||
| 39 | else { | ||||||||||||||
| 40 | 1 | return $class->wantscalar( $code, @args ); | |||||||||||||
| 41 | } | ||||||||||||||
| 42 | } | ||||||||||||||
| 43 | |||||||||||||||
| 44 | 5 | ▶ | sub result { | ||||||||||||
|
Subroutine
result: called CC=4 SCAR=14.0
Pod
documented
| |||||||||||||||
| 45 | 5 | my ($self) = @_; | |||||||||||||
| 46 | 5 | ▶ | if ( exists $self->{error} ) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 47 | 1 | die $self->{error}; | |||||||||||||
| 48 | } | ||||||||||||||
| 49 | else { | ||||||||||||||
| 50 | 4 | my $result = delete $self->{result}; | |||||||||||||
| 51 | 4 | ▶ | if ( ref $result eq 'ARRAY' ) { | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 52 | 2 | return @$result; | |||||||||||||
| 53 | } | ||||||||||||||
| 54 | elsif ( ref $result eq 'SCALAR' ) { | ||||||||||||||
| 55 | 2 | return $$result; | |||||||||||||
| 56 | } | ||||||||||||||
| 57 | else { | ||||||||||||||
| 58 | 0 | return; | |||||||||||||
| 59 | } | ||||||||||||||
| 60 | } | ||||||||||||||
| 61 | } | ||||||||||||||
| 62 | |||||||||||||||
| 63 | 4 | 1; | |||||||||||||
| 64 | |||||||||||||||
| 65 | __END__ | ||||||||||||||