| 1 | package Throwable::SysError; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 2 | ▶ | use namespace::autoclean; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 2 | ▶ | use Errno qw(); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 2 | ▶ | use Moo; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 2 | ▶ | use MooX::Types::MooseLike::Base qw( Int Str ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 2 | ▶ | use Scalar::Util qw(); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | 2 | extends qw( Throwable::Error ); | |||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | 2 | our $VERSION = '0.00'; | |||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | 2 | has op => ( is => 'ro', isa => Str, required => 1 ); | |||||||||||||||||||||||||||
| 15 | 2 | has errno => ( is => 'ro', isa => Int, required => 1 ); | |||||||||||||||||||||||||||
| 16 | 2 | has errstr => ( is => 'ro', isa => Str, required => 1 ); | |||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | 6 | ▶ | around BUILDARGS => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 20 | 6 | my ( $orig, $class ) = ( shift, shift ); | |||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | 6 | my $args = $class->$orig( @_ ); | |||||||||||||||||||||||||||
| 23 | my $_errno = defined $args->{_errno} | ||||||||||||||||||||||||||||
| 24 | 6 | ▶ | ? do { local $! = $args->{_errno}; $! } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 25 | : $! | ||||||||||||||||||||||||||||
| 26 | ; | ||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | 6 | @$args{qw( errno errstr )} | |||||||||||||||||||||||||||
| 29 | = ( 0 + $_errno, ''. $_errno ); | ||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | 6 | $args | |||||||||||||||||||||||||||
| 32 | 2 | }; | |||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | 6 | ▶ | around throw => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||
| 35 | 6 | my ( $orig, $invocant ) = ( shift, shift ); | |||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | # save $! as soon as possible | ||||||||||||||||||||||||||||
| 38 | 6 | my $_errno = $!; | |||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | # pass-through on re-throw | ||||||||||||||||||||||||||||
| 41 | 6 | ▶ | return $invocant->$orig( @_ ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 42 | if Scalar::Util::blessed( $invocant ); | ||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | # fix up @_ to include _errno | ||||||||||||||||||||||||||||
| 45 | 5 | ▶ | if( @_ == 1 ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 46 | # inject _errno if we have a single hash argument. | ||||||||||||||||||||||||||||
| 47 | # otherwise we don't know what to do. | ||||||||||||||||||||||||||||
| 48 | $_[0]->{_errno} = $_errno | ||||||||||||||||||||||||||||
| 49 | 3 | ▶ | if ref $_[0] eq 'HASH' && ! defined $_[0]->{_errno}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
ref $_[0] eq "HASH" and not defined $_[0]{"_errno"}
MC/DC100%2/2
ref $_[0] eq "HASH" and not defined $_[0]{"_errno"}
ref $_[0] eq "HASH"
not defined $_[0]{"_errno"}
Truth table100%3/3
A and not(B)
A= ref $_[0] eq "HASH"B= not defined $_[0]{"_errno"}
| |||||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||
| 51 | else { | ||||||||||||||||||||||||||||
| 52 | # inject _errno at the front of the list to allow | ||||||||||||||||||||||||||||
| 53 | # overriding when in new() | ||||||||||||||||||||||||||||
| 54 | 2 | unshift @_, _errno => $_errno; | |||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | 5 | $invocant->$orig( @_ ) | |||||||||||||||||||||||||||
| 58 | 2 | }; | |||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | 2 | ▶ | sub is { | ||||||||||||||||||||||||||
|
Subroutine
is: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 61 | 2 | my ( $self, $errname ) = @_; | |||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | 2 | local $! = $self->errno; | |||||||||||||||||||||||||||
| 64 | 2 | $!{$errname} | |||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | 2 | 1 | |||||||||||||||||||||||||||
| 69 | __END__ | ||||||||||||||||||||||||||||