blib/lib/Pinto/Result.pm

filter: Statementstmt 97.6% 41 / 42 Branchbran 80.0% 8 / 10 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 11 / 11 Podpod 0.0% 0 / 4 totaltotal 89.5% 60 / 67 CC 6 SCAR 6.4
CC
6
Cov
94%
to_string
3.1
failed
3.0
exit_status
2.1
CRAP 1.9
« blib/lib/Pinto/Initializer.pm ↑ Summary blib/lib/Pinto/Server.pm »
1 # ABSTRACT: The result from running an Action
2  
3 package Pinto::Result;
4  
5 95 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 95 ▶use MooseX::StrictConstructor;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 95 ▶use MooseX::Types::Moose qw(Bool ArrayRef);
Subroutine BEGIN: called CC=1 SCAR=0.0
8 95 ▶use MooseX::MarkAsMethods ( autoclean => 1 );
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 95 ▶use Pinto::Util qw(itis);
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 95 ▶use overload ( q{""} => 'to_string' );
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 #-----------------------------------------------------------------------------
15  
16 95 our $VERSION = '0.14'; # VERSION
17  
18 #------------------------------------------------------------------------------
19  
20 95 has made_changes => (
21 is => 'ro',
22 isa => Bool,
23 writer => '_set_made_changes',
24 default => 0,
25 );
26  
27 95 has was_successful => (
28 is => 'ro',
29 isa => Bool,
30 writer => '_set_was_successful',
31 default => 1,
32 );
33  
34 has exceptions => (
35 traits => [qw(Array)],
36 handles => { exceptions => 'elements', add_exception => 'push' },
37 isa => ArrayRef,
38 205 ▶ default => sub { [] },
Subroutine __ANON__: called CC=1 SCAR=0.0
39 95 );
40  
41 #-----------------------------------------------------------------------------
42  
43 87 ▶sub failed {
Subroutine failed: called CC=3 SCAR=11.0
Pod undocumented
44 87 my ( $self, %args ) = @_;
45  
46 87 $self->_set_was_successful(0);
47  
48 87 ▶ if ( my $reason = $args{because} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $reason = $args{"because"}) 83 4 87
49  
50 # HACK: Sometimes we'll get exceptions that are strings
51 # instead of objects (like from Moose type constraint
52 # violations). So we have to convert them ourselves.
53 # If the message already contains a full stack trace,
54 # then it will be really ugly. God I wish Perl had
55 # sane native exceptions.
56  
57 83 require Pinto::Exception;
58  
59 83 ▶ $reason = Pinto::Exception->new( message => "$reason" )
Branch: 1 branch
BranchTrueFalseTotal
unless itis($reason, "Pinto::Exception") 5 78 83
60 if not itis( $reason, 'Pinto::Exception' );
61  
62 83 $self->add_exception($reason);
63 }
64  
65 87 return $self;
66 }
67  
68 #-----------------------------------------------------------------------------
69  
70 101 ▶sub changed {
Subroutine changed: called CC=1 SCAR=0.0
Pod undocumented
71 101 my ($self) = @_;
72  
73 101 $self->_set_made_changes(1);
74  
75 101 return $self;
76 }
77  
78 #-----------------------------------------------------------------------------
79  
80 2 ▶sub exit_status {
Subroutine exit_status: called CC=2 SCAR=7.2
Pod undocumented
81 2 my ($self) = @_;
82  
83 2 ▶ return $self->was_successful ? 0 : 1;
Branch: 1 branch
BranchTrueFalseTotal
$self->was_successful ? : 2 0 2
84 }
85  
86 #-----------------------------------------------------------------------------
87  
88 24 ▶sub to_string {
Subroutine to_string: called CC=3 SCAR=11.3
Pod undocumented
89 24 my ($self) = @_;
90  
91 24 ▶ return 'ok' if $self->was_successful;
Branch: 1 branch
BranchTrueFalseTotal
if $self->was_successful 1 23 24
92  
93 23 ▶ if ( my @exceptions = $self->exceptions ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my(@exceptions) = $self->exceptions) 23 0 23
94 23 return join "\n", @exceptions;
95 }
96  
97 0 return 'unknown error';
98 }
99  
100 #-----------------------------------------------------------------------------
101  
102 95 __PACKAGE__->meta->make_immutable;
103  
104 #-----------------------------------------------------------------------------
105 95 1;
106  
107 __END__
« blib/lib/Pinto/Initializer.pm ↑ Summary blib/lib/Pinto/Server.pm »