| 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.000015'; # 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 | 67 | ▶ | sub target { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
target: called CC=7 SCAR=20.5
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 69 | 67 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 70 | 67 | ▶ | if (@_) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 71 | 13 | my $candidate = shift; | |||||||||||||||||||||||||||||||||||||||||
| 72 | 13 | ▶ | croak "targets must not be falsy" unless $candidate; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 73 | 13 | ▶ | if(eval { $candidate->DOES('Path::Class::File') || | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%3/6
$candidate->DOES('Path::Class::File') || $candidate->DOES('Path::Class::Dir') || $candidate->DOES('App::hopen::Util::BasedPath')
$candidate->DOES("Path::Class::File") or $candidate->DOES("Path::Class::Dir")
MC/DC33%1/3
$candidate->DOES('Path::Class::File') || $candidate->DOES('Path::Class::Dir') || $candidate->DOES('App::hopen::Util::BasedPath')
$candidate->DOES("Path::Class::File")
$candidate->DOES("Path::Class::Dir")
$candidate->DOES('App::hopen::Util::BasedPath')
Truth table50%2/4
A or B || C
A= $candidate->DOES("Path::Class::File")B= $candidate->DOES("Path::Class::Dir")C= $candidate->DOES('App::hopen::Util::BasedPath')
| |||||||||||||||||||||||||||||||||||||||||||
| 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 | 3 | ▶ | use Class::Tiny::ConstrainedAccessor [NOBUILD => true], | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 90 | 18 | ▶ | made_by => [ sub { eval { $_[0]->DOES('App::hopen::G::Cmd') } }, | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 91 | 0 | ▶ | sub { 'made_by values must implement App::hopen::G::Cmd' } ]; | ||||||||||||||||||||||||||||||||||||||||
|
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 | 6 | ▶ | sub isdisk { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
isdisk: called CC=4 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 104 | 6 | ▶ | my $self = shift or croak 'Need an instance'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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')
$self->target->DOES("Path::Class::File") or $self->target->DOES("Path::Class::Dir")
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')
| |||||||||||||||||||||||||||||||||||||||||||
| 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 | 13 | ▶ | sub BUILD { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BUILD: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 120 | 13 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 121 | 13 | ▶ | $self->name('__R_Asset_' . $_id_counter++) unless $self->name; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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__ | ||||||||||||||||||||||||||||||||||||||||||