| 1 | # App::hopen::G::Cmd - base class for hopen(1) command-graph nodes | ||||||||||||||
| 2 | package App::hopen::G::Cmd; | ||||||||||||||
| 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 | 3 | ▶ | use Quote::Code; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 6 | |||||||||||||||
| 7 | 3 | our $VERSION = '0.000013'; # TRIAL | |||||||||||||
| 8 | |||||||||||||||
| 9 | 3 | ▶ | use parent 'Data::Hopen::G::Op'; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 10 | use Class::Tiny { | ||||||||||||||
| 11 | 22 | ▶ | made => sub { [] }, | ||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||
| 12 | 3 | ▶ | }; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 13 | |||||||||||||||
| 14 | 3 | ▶ | use Class::Method::Modifiers qw(around); | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 15 | 3 | ▶ | use Data::Hopen qw(getparameters); | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 16 | |||||||||||||||
| 17 | # Docs {{{1 | ||||||||||||||
| 18 | |||||||||||||||
| 19 | =head1 NAME | ||||||||||||||
| 20 | |||||||||||||||
| 21 | App::hopen::G::Cmd - base class for hopen(1) command-graph nodes | ||||||||||||||
| 22 | |||||||||||||||
| 23 | =head1 SYNOPSIS | ||||||||||||||
| 24 | |||||||||||||||
| 25 | This is the base class for graph nodes in the command graph of | ||||||||||||||
| 26 | L<App::hopen>. See L<App::hopen::Conventions>. | ||||||||||||||
| 27 | |||||||||||||||
| 28 | =head1 ATTRIBUTES | ||||||||||||||
| 29 | |||||||||||||||
| 30 | =head2 made | ||||||||||||||
| 31 | |||||||||||||||
| 32 | An arrayref of the outputs from this function, which are L<App::hopen::Asset> | ||||||||||||||
| 33 | instances. | ||||||||||||||
| 34 | |||||||||||||||
| 35 | =cut | ||||||||||||||
| 36 | |||||||||||||||
| 37 | # }}}1 | ||||||||||||||
| 38 | |||||||||||||||
| 39 | =head1 FUNCTIONS | ||||||||||||||
| 40 | |||||||||||||||
| 41 | =head2 make | ||||||||||||||
| 42 | |||||||||||||||
| 43 | Adds L<App::hopen::Asset> instances to L</made> (a L<Cmd|App::hopen::G::Cmd>'s | ||||||||||||||
| 44 | asset output). B<Does not> add the assets to the generator's asset graph, | ||||||||||||||
| 45 | since the generator is not available as instance data. One or more parameters | ||||||||||||||
| 46 | or arrayrefs of parameters can be given. Returns a list of the C<Asset> | ||||||||||||||
| 47 | instances made. Each parameter can be: | ||||||||||||||
| 48 | |||||||||||||||
| 49 | =over | ||||||||||||||
| 50 | |||||||||||||||
| 51 | =item * | ||||||||||||||
| 52 | |||||||||||||||
| 53 | An L<App::hopen::Asset> or subclass (in which case | ||||||||||||||
| 54 | L<made_by|App::hopen::Asset/made_by> is updated) | ||||||||||||||
| 55 | |||||||||||||||
| 56 | =item * | ||||||||||||||
| 57 | |||||||||||||||
| 58 | A valid C<target> for an L<App::hopen::Asset>. | ||||||||||||||
| 59 | |||||||||||||||
| 60 | =back | ||||||||||||||
| 61 | |||||||||||||||
| 62 | =cut | ||||||||||||||
| 63 | |||||||||||||||
| 64 | sub make { | ||||||||||||||
| 65 | 25 | ▶ | my $self = shift or croak 'Need an instance'; | ||||||||||||
|
Subroutine
make: called CC=5 SCAR=16.1
Pod
documented
Branch: 1 branch
| |||||||||||||||
| 66 | 25 | my @retval; | |||||||||||||
| 67 | 25 | for my $arg (@_) { | |||||||||||||
| 68 | 25 | ▶ | if(ref $arg eq 'ARRAY') { | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 69 | 3 | push @retval, $self->make(@$arg); | |||||||||||||
| 70 | 22 | } elsif(eval { $arg->DOES('App::hopen::Asset') }) { | |||||||||||||
| 71 | 18 | $arg->made_by($self); | |||||||||||||
| 72 | 18 | push @{$self->made}, $arg; | |||||||||||||
| 73 | 18 | push @retval, $arg; | |||||||||||||
| 74 | } else { | ||||||||||||||
| 75 | 4 | my $asset = App::hopen::Asset->new(target=>$arg, made_by=>$self); | |||||||||||||
| 76 | 4 | push @{$self->made}, $asset; | |||||||||||||
| 77 | 4 | push @retval, $asset; | |||||||||||||
| 78 | } | ||||||||||||||
| 79 | } #foreach arg | ||||||||||||||
| 80 | 25 | return @retval; | |||||||||||||
| 81 | } #make() | ||||||||||||||
| 82 | |||||||||||||||
| 83 | =head2 input_assets | ||||||||||||||
| 84 | |||||||||||||||
| 85 | Returns the assets provided as input via L</make> calls in predecessor nodes. | ||||||||||||||
| 86 | Only meaningful within C<_run()> (since that's when C<< $self->scope >> | ||||||||||||||
| 87 | is populated). Returns an arrayref in scalar context or a list in list context. | ||||||||||||||
| 88 | |||||||||||||||
| 89 | =cut | ||||||||||||||
| 90 | |||||||||||||||
| 91 | sub input_assets { | ||||||||||||||
| 92 | 18 | ▶ | my $self = shift or croak 'Need an instance'; | ||||||||||||
|
Subroutine
input_assets: called CC=5 SCAR=16.1
Pod
documented
Branch: 1 branch
| |||||||||||||||
| 93 | 18 | my $lrSourceFiles; | |||||||||||||
| 94 | |||||||||||||||
| 95 | 18 | ▶ | my $hrSourceFiles = | ||||||||||||
|
Condition100%2/2
$self->scope->find("-name", "made", "-set", "*", "-levels", "local") // {}
MC/DC100%1/1
$self->scope->find("-name", "made", "-set", "*", "-levels", "local") // {}
$self->scope->find("-name", "made", "-set", "*", "-levels", "local")
Truth table100%2/2
A
A= $self->scope->find("-name", "made", "-set", "*", "-levels", "local")
| |||||||||||||||
| 96 | $self->scope->find(-name => 'made', -set => '*', -levels => 'local') // {}; | ||||||||||||||
| 97 | |||||||||||||||
| 98 | 18 | ▶ | if(keys %$hrSourceFiles) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 99 | 15 | $lrSourceFiles = $hrSourceFiles->{(keys %$hrSourceFiles)[0]}; | |||||||||||||
| 100 | } else { | ||||||||||||||
| 101 | 3 | $lrSourceFiles = []; | |||||||||||||
| 102 | } | ||||||||||||||
| 103 | |||||||||||||||
| 104 | 18 | ▶ | return $lrSourceFiles unless wantarray; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 105 | 12 | return @$lrSourceFiles; | |||||||||||||
| 106 | } #input_assets() | ||||||||||||||
| 107 | |||||||||||||||
| 108 | =head2 run | ||||||||||||||
| 109 | |||||||||||||||
| 110 | Overrides L<Data::Hopen::G::Runnable/run> to stuff L</made> into the | ||||||||||||||
| 111 | outputs if it's not already there. Note that this will B<replace> | ||||||||||||||
| 112 | any non-arrayref C<made> output. | ||||||||||||||
| 113 | |||||||||||||||
| 114 | =cut | ||||||||||||||
| 115 | |||||||||||||||
| 116 | around 'run' => sub { | ||||||||||||||
| 117 | 22 | ▶ | my $orig = shift; | ||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.3
| |||||||||||||||
| 118 | 22 | ▶ | my $self = shift or croak 'Need an instance'; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 119 | 22 | my $retval = $self->$orig(@_); | |||||||||||||
| 120 | |||||||||||||||
| 121 | 22 | ▶ | $retval->{made} = $self->made unless ref $retval->{made} eq 'ARRAY'; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 122 | # TODO clone? Shallow copy? | ||||||||||||||
| 123 | 22 | return $retval; | |||||||||||||
| 124 | 3 | }; #run() | |||||||||||||
| 125 | |||||||||||||||
| 126 | 3 | 1; | |||||||||||||
| 127 | __END__ | ||||||||||||||
| 128 | # vi: set fdm=marker: # | ||||||||||||||