| 1 | 12 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 2 | 12 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 3 | |||||||||||
| 4 | package Footprintless::CommandRunner::ExecutionException; | ||||||||||
| 5 | 12 | $Footprintless::CommandRunner::ExecutionException::VERSION = '1.29'; | |||||||||
| 6 | # ABSTRACT: An exception for failures when executing commands | ||||||||||
| 7 | # PODNAME: Footprintless::CommandRunner::ExecutionException | ||||||||||
| 8 | |||||||||||
| 9 | 12 | ▶ | use Term::ANSIColor; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | 12 | ▶ | use overload '""' => 'to_string'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 11 | |||||||||||
| 12 | 6 | ▶ | sub new { | ||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 13 | 6 | return bless( {}, shift )->_init(@_); | |||||||||
| 14 | } | ||||||||||
| 15 | |||||||||||
| 16 | 6 | ▶ | sub _init { | ||||||||
|
Subroutine
_init: called CC=1 SCAR=0.0
| |||||||||||
| 17 | 6 | my ( $self, $command, $exit_code, $message, $stderr ) = @_; | |||||||||
| 18 | |||||||||||
| 19 | 6 | $self->{command} = $command; | |||||||||
| 20 | 6 | $self->{exit_code} = $exit_code; | |||||||||
| 21 | 6 | $self->{message} = $message; | |||||||||
| 22 | 6 | $self->{stderr} = $stderr; | |||||||||
| 23 | 6 | $self->{trace} = []; | |||||||||
| 24 | |||||||||||
| 25 | 6 | return $self; | |||||||||
| 26 | } | ||||||||||
| 27 | |||||||||||
| 28 | 0 | ▶ | sub exit { | ||||||||
|
Subroutine
exit: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||
| 29 | 0 | my ( $self, $verbose ) = @_; | |||||||||
| 30 | 0 | ▶ | print( STDERR "$self->{message}\n" ) if ( $self->{message} ); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 31 | 0 | ▶ | print( STDERR "$self->{stderr}\n" ) if ( $self->{stderr} ); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 32 | 0 | ▶ | if ($verbose) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 33 | 0 | print( STDERR colored( ['red'], "[$self->{command}]" ), | |||||||||
| 34 | " failed ($self->{exit_code})\n" ); | ||||||||||
| 35 | 0 | print( STDERR $self->_trace_string(), "\n" ); | |||||||||
| 36 | } | ||||||||||
| 37 | 0 | exit $self->{exit_code}; | |||||||||
| 38 | } | ||||||||||
| 39 | |||||||||||
| 40 | 0 | ▶ | sub get_command { | ||||||||
|
Subroutine
get_command: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 41 | 0 | return $_[0]->{command}; | |||||||||
| 42 | } | ||||||||||
| 43 | |||||||||||
| 44 | 2 | ▶ | sub get_exit_code { | ||||||||
|
Subroutine
get_exit_code: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 45 | 2 | return $_[0]->{exit_code}; | |||||||||
| 46 | } | ||||||||||
| 47 | |||||||||||
| 48 | 0 | ▶ | sub get_message { | ||||||||
|
Subroutine
get_message: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 49 | 0 | return $_[0]->{message}; | |||||||||
| 50 | } | ||||||||||
| 51 | |||||||||||
| 52 | 0 | ▶ | sub get_stderr { | ||||||||
|
Subroutine
get_stderr: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 53 | 0 | return $_[0]->{stderr}; | |||||||||
| 54 | } | ||||||||||
| 55 | |||||||||||
| 56 | 0 | ▶ | sub get_trace { | ||||||||
|
Subroutine
get_trace: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 57 | 0 | return $_[0]->{trace}; | |||||||||
| 58 | } | ||||||||||
| 59 | |||||||||||
| 60 | 0 | ▶ | sub PROPAGATE { | ||||||||
|
Subroutine
PROPAGATE: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 61 | 0 | my ( $self, $file, $line ) = @_; | |||||||||
| 62 | 0 | push( @{ $self->{trace} }, [ $file, $line ] ); | |||||||||
| 63 | } | ||||||||||
| 64 | |||||||||||
| 65 | 7 | ▶ | sub to_string { | ||||||||
|
Subroutine
to_string: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||
| 66 | 7 | my ($self) = @_; | |||||||||
| 67 | |||||||||||
| 68 | 7 | my @parts = ( $self->{exit_code} ); | |||||||||
| 69 | 7 | ▶ | push( @parts, ": $self->{message}" ) if ( $self->{message} ); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 70 | push( @parts, "\n****STDERR****\n$self->{stderr}\n****STDERR****" ) | ||||||||||
| 71 | 7 | ▶ | if ( $self->{stderr} ); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 72 | 7 | push( @parts, "\n", $self->_trace_string() ); | |||||||||
| 73 | |||||||||||
| 74 | 7 | return join( '', @parts ); | |||||||||
| 75 | } | ||||||||||
| 76 | |||||||||||
| 77 | 7 | ▶ | sub _trace_string { | ||||||||
|
Subroutine
_trace_string: called CC=3 SCAR=14.2
| |||||||||||
| 78 | 7 | my ($self) = @_; | |||||||||
| 79 | 7 | my @parts = (); | |||||||||
| 80 | 7 | ▶ | if ( @{ $self->{trace} } ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 81 | 0 | push( @parts, "****TRACE****" ); | |||||||||
| 82 | 0 | foreach my $stop ( @{ $self->{trace} } ) { | |||||||||
| 83 | 0 | push( @parts, "$stop->[0]($stop->[1])" ); | |||||||||
| 84 | } | ||||||||||
| 85 | 0 | push( @parts, "\n****TRACE****" ); | |||||||||
| 86 | } | ||||||||||
| 87 | 7 | return join( '', @parts ); | |||||||||
| 88 | } | ||||||||||
| 89 | |||||||||||
| 90 | 12 | 1; | |||||||||
| 91 | |||||||||||
| 92 | __END__ | ||||||||||