File Coverage

blib/lib/Path/IsDev/Result.pm
Criterion Covered Total %
statement 40 44 90.9
branch 8 14 57.1
condition n/a
subroutine 9 10 90.0
pod 2 2 100.0
total 59 70 84.2


line stmt bran cond sub pod time code
1 12     12   545 use 5.008;
  12         26  
2 12     12   41 use strict;
  12         17  
  12         204  
3 12     12   36 use warnings;
  12         13  
  12         250  
4 12     12   470 use utf8;
  12         21  
  12         50  
5              
6             package Path::IsDev::Result;
7              
8             our $VERSION = '1.001003';
9              
10             # ABSTRACT: Result container
11              
12             our $AUTHORITY = 'cpan:KENTNL'; # AUTHORITY
13              
14              
15              
16              
17              
18              
19              
20              
21              
22              
23              
24              
25              
26              
27              
28              
29              
30              
31              
32              
33              
34              
35              
36              
37              
38              
39              
40              
41              
42              
43              
44 12     12   1107 use Class::Tiny 'path', 'result', { reasons => sub { [] }, };
  12         2073  
  12         82  
  16         138  
45              
46 2     2   623 sub _path { require Path::Tiny; goto &Path::Tiny::path }
  2         7944  
47 0     0   0 sub _croak { require Carp; goto &Carp::croak }
  0         0  
48             ## no critic (Subroutines::ProhibitCallsToUnexportedSubs)
49 216     216   496 sub _debug { require Path::IsDev; shift; goto &Path::IsDev::debug }
  216         182  
  216         490  
50              
51              
52              
53              
54              
55             sub BUILD {
56 16     16 1 849 my ( $self, ) = @_;
57 16 50       307 if ( not $self->path ) {
58 0         0 return _croak(q[ is a mandatory parameter]);
59             }
60 16 100       368 if ( not ref $self->path ) {
61 2         58 $self->path( _path( $self->path ) );
62             }
63 16 50       329 if ( not -e $self->path ) {
64 0         0 return _croak(q[ parameter must exist for heuristics to be performed]);
65             }
66 16         719 $self->path( $self->path->absolute );
67 16         832 return $self;
68             }
69              
70              
71              
72              
73              
74              
75              
76              
77              
78              
79              
80              
81              
82              
83              
84              
85              
86              
87              
88              
89              
90              
91              
92              
93              
94              
95              
96              
97              
98              
99              
100              
101             sub add_reason {
102 216     216 1 715 my ( $self, $heuristic_name, $heuristic_result, $summary, $context ) = @_;
103 216         246 my $name = $heuristic_name;
104 216 50       942 if ( $name->can('name') ) {
105 216         481 $name = $name->name;
106             }
107 216         607 $self->_debug("$name => $heuristic_result : $summary ");
108              
109             # $self->_debug( " > " . $_) for _pp($context);
110 216         166 my ($heuristic_type);
111              
112 216 50       707 if ( $heuristic_name->can(q[heuristic_type]) ) {
113 216         401 $heuristic_type = $heuristic_name->heuristic_type;
114             }
115              
116             my $reason = {
117             heuristic => $heuristic_name,
118             result => $heuristic_result,
119             ( defined $heuristic_type ? ( type => $heuristic_type ) : () ),
120 216 50       378 %{ $context || {} },
  216 50       1035  
121             };
122 216         210 push @{ $self->reasons }, $reason;
  216         3940  
123 216         991 return $self;
124             }
125              
126             1;
127              
128             __END__