blib/lib/App/hopen/Asset.pm

filter: Statementstmt 95.0% 38 / 40 Branchbran 64.2% 9 / 14 Conditioncond 33.3% 3 / 9 MC/DCmcdc 0.0% 0 / 5 Subroutinesub 90.9% 10 / 11 Podpod 100% 3 / 3 totaltotal 76.8% 63 / 82 CC 11 SCAR 14.7
CC
11
Cov
79%
target
7.9
isdisk
6.0
BUILD
2.0
CRAP 4.3
« blib/lib/App/hopen/Util/String.pm ↑ Summary blib/lib/App/hopen/T/MSCL/C.pm »
1 # App::hopen::Asset - record representing a file to be produced
2 package App::hopen::Asset;
3 3 ▶use strict; use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
4 3 ▶use Data::Hopen::Base;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 3 ▶use Path::Class;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 # and we use Class::Tiny below.
8  
9 3 our $VERSION = '0.000013'; # TRIAL
10  
11 # Docs {{{1
12  
13 =head1 NAME
14  
15 App::hopen::Asset - record representing a file to be produced
16  
17 =head1 SYNOPSIS
18  
19 An asset is something to be produced, e.g., a file on disk or something
20 else that could be a target in a Makefile.
21  
22 =head1 ATTRIBUTES
23  
24 =head2 target
25  
26 TODO: should on-disk targets be required to be BasedPath instances?
27  
28 The name of the asset. Must be one of:
29  
30 =over
31  
32 =item *
33  
34 A L<Path::Class> instance, representing a file or directory on disk
35  
36 =item *
37  
38 An L<App::hopen::Util::BasedPath> instance, representing a file or directory
39 on disk
40  
41 =item *
42  
43 Something that stringifies to a non-disk target (e.g., a goal). Anything in
44 this category will be stored as its stringified value, NOT as its original
45 value.
46  
47 =back
48  
49 No default, so don't call C<< $obj->target >> until you've assigned a target!
50  
51 =head2 made_by
52  
53 The L<App::hopen::G::Cmd> (or subclass) instance that produced this asset.
54 Used to distinguish assets from different sources.
55  
56 =head2 name
57  
58 An optional asset name. If you don't specify one, a unique one will be
59 generated automatically.
60  
61 =head1 METHODS
62  
63 =cut
64  
65 # }}}1
66  
67 # The accessor for the target attribute.
68 sub target {
69 67 ▶ my $self = shift;
Subroutine target: called CC=7 SCAR=20.6
Pod documented
70 67 ▶ if (@_) {
Branch: 2 branches
BranchTrueFalseTotal
if (@_) { } 13 54 67
elsif (exists $self->{'target'}) { } 54 0 54
71 13 my $candidate = shift;
72 13 ▶ croak "targets must not be falsy" unless $candidate;
Branch: 1 branch
BranchTrueFalseTotal
unless $candidate 0 13 13
73 13 ▶ if(eval { $candidate->DOES('Path::Class::File') ||
Branch: 2 branches
BranchTrueFalseTotal
if (eval { do { $candidate->DOES('Path::Class::File') or $candidate->DOES('Path::Class::Dir') or $candidate->DOES('App::hopen::Util::BasedPath') } }) { } 10 3 13
$candidate->DOES("Path::Class::File") or $candidate->DOES("Path::Class::Dir") or $candidate->DOES("App::hopen::Util::BasedPath") 13 0 13
Condition33%1/3
$candidate->DOES("Path::Class::File") or $candidate->DOES("Path::Class::Dir")
l!l&&r!l&&!r
0013
MC/DC0%0/2
$candidate->DOES("Path::Class::File") or $candidate->DOES("Path::Class::Dir")
$candidate->DOES("Path::Class::File") $candidate->DOES("Path::Class::Dir")
Truth table33%1/3
A or B
A= $candidate->DOES("Path::Class::File")B= $candidate->DOES("Path::Class::Dir")
ABresult
1X1
011
000
74 $candidate->DOES('Path::Class::Dir') ||
75 $candidate->DOES('App::hopen::Util::BasedPath' ) }
76 ) {
77 10 return $self->{target} = $candidate;
78 } else {
79 3 return $self->{target} = "$candidate";
80 }
81 } elsif ( exists $self->{target} ) {
82 54 return $self->{target};
83 } else { # No default.
84 0 croak "I don't have a target to give you";
85 }
86 } #target()
87  
88 # Create the accessor that enforces the restriction on made_by
89 use Class::Tiny::ConstrainedAccessor [NOBUILD => true],
90 18 ▶ made_by => [ sub { eval { $_[0]->DOES('App::hopen::G::Cmd') } },
Subroutine __ANON__: called CC=1 SCAR=0.0
91 3 ▶ sub { 'made_by values must implement App::hopen::G::Cmd' } ];
Subroutine BEGIN: called CC=1 SCAR=0.2
Subroutine __ANON__: not called CC=1 SCAR=0.2
92  
93 # Set up the rest of the class
94 3 ▶use Class::Tiny qw(target made_by name);
Subroutine BEGIN: called CC=1 SCAR=0.0
95  
96 =head2 isdisk
97  
98 Returns truthy if the L</target> is an on-disk entity, i.e., a
99 directory or file.
100  
101 =cut
102  
103 sub isdisk {
104 6 ▶ my $self = shift or croak 'Need an instance';
Subroutine isdisk: called CC=4 SCAR=17.9
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
my $self = shift() or croak("Need an instance") 0 6 6
105 6 ▶ return ($self->target->DOES('Path::Class::File') ||
Condition33%2/6
$self->target->DOES('Path::Class::File') || $self->target->DOES('Path::Class::Dir') || $self->target->DOES('App::hopen::Util::BasedPath')
l!l&&r!l&&!r
060
$self->target->DOES("Path::Class::File") or $self->target->DOES("Path::Class::Dir")
l!l&&r!l&&!r
006
MC/DC0%0/3
$self->target->DOES('Path::Class::File') || $self->target->DOES('Path::Class::Dir') || $self->target->DOES('App::hopen::Util::BasedPath')
$self->target->DOES("Path::Class::File") $self->target->DOES("Path::Class::Dir") $self->target->DOES('App::hopen::Util::BasedPath')
Truth table25%1/4
A or B || C
A= $self->target->DOES("Path::Class::File")B= $self->target->DOES("Path::Class::Dir")C= $self->target->DOES('App::hopen::Util::BasedPath')
ABCresult
1XX1
01X1
0011
0000
106 $self->target->DOES('Path::Class::Dir') ||
107 $self->target->DOES('App::hopen::Util::BasedPath')
108 );
109 } #isdisk()
110  
111 =head2 BUILD
112  
113 Enforces the requirement for C<target> and C<made_by>.
114  
115 =cut
116  
117 3 my $_id_counter;
118  
119 sub BUILD {
120 13 ▶ my ($self) = @_;
Subroutine BUILD: called CC=2 SCAR=7.0
Pod documented
121 13 ▶ $self->name('__R_Asset_' . $_id_counter++) unless $self->name;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->name 13 0 13
122 13 $self->target($self->{target}); # Check the custom constraint on target
123 # by re-setting target.
124 13 $self->_check_all_constraints(); # Checks made_by.
125 } #BUILD()
126  
127 3 1;
128 __END__
129 # vi: set fdm=marker: #
« blib/lib/App/hopen/Util/String.pm ↑ Summary blib/lib/App/hopen/T/MSCL/C.pm »