| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | # App::hopen::G::Cmd - base class for hopen(1) command-graph nodes | 
| 2 |  |  |  |  |  |  | package App::hopen::G::Cmd; | 
| 3 | 3 |  |  | 3 |  | 1302 | use strict; | 
|  | 3 |  |  |  |  | 8 |  | 
|  | 3 |  |  |  |  | 86 |  | 
| 4 | 3 |  |  | 3 |  | 15 | use Data::Hopen::Base; | 
|  | 3 |  |  |  |  | 5 |  | 
|  | 3 |  |  |  |  | 22 |  | 
| 5 | 3 |  |  | 3 |  | 4382 | use Quote::Code; | 
|  | 3 |  |  |  |  | 698 |  | 
|  | 3 |  |  |  |  | 15 |  | 
| 6 |  |  |  |  |  |  |  | 
| 7 |  |  |  |  |  |  | our $VERSION = '0.000011'; | 
| 8 |  |  |  |  |  |  |  | 
| 9 | 3 |  |  | 3 |  | 172 | use parent 'Data::Hopen::G::Op'; | 
|  | 3 |  |  |  |  | 7 |  | 
|  | 3 |  |  |  |  | 18 |  | 
| 10 |  |  |  |  |  |  | use Class::Tiny { | 
| 11 | 13 |  |  |  |  | 140 | made => sub { [] }, | 
| 12 | 3 |  |  | 3 |  | 109171 | }; | 
|  | 3 |  |  |  |  | 8 |  | 
|  | 3 |  |  |  |  | 36 |  | 
| 13 |  |  |  |  |  |  |  | 
| 14 | 3 |  |  | 3 |  | 2121 | use Class::Method::Modifiers qw(around); | 
|  | 3 |  |  |  |  | 4863 |  | 
|  | 3 |  |  |  |  | 190 |  | 
| 15 | 3 |  |  | 3 |  | 22 | use Data::Hopen qw(getparameters); | 
|  | 3 |  |  |  |  | 9 |  | 
|  | 3 |  |  |  |  | 1602 |  | 
| 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 | 15 | 50 |  | 15 | 1 | 385 | my $self = shift or croak 'Need an instance'; | 
| 66 | 15 |  |  |  |  | 265 | my @retval; | 
| 67 | 15 |  |  |  |  | 47 | for my $arg (@_) { | 
| 68 | 15 | 100 |  |  |  | 89 | if(ref $arg eq 'ARRAY') { | 
|  |  | 100 |  |  |  |  |  | 
| 69 | 2 |  |  |  |  | 12 | push @retval, $self->make(@$arg); | 
| 70 | 13 |  |  |  |  | 90 | } elsif(eval { $arg->DOES('App::hopen::Asset') }) { | 
| 71 | 10 |  |  |  |  | 43 | $arg->made_by($self); | 
| 72 | 10 |  |  |  |  | 52 | push @{$self->made}, $arg; | 
|  | 10 |  |  |  |  | 236 |  | 
| 73 | 10 |  |  |  |  | 32 | push @retval, $arg; | 
| 74 |  |  |  |  |  |  | } else { | 
| 75 | 3 |  |  |  |  | 25 | my $asset = App::hopen::Asset->new(target=>$arg, made_by=>$self); | 
| 76 | 3 |  |  |  |  | 46 | push @{$self->made}, $asset; | 
|  | 3 |  |  |  |  | 77 |  | 
| 77 | 3 |  |  |  |  | 12 | push @retval, $asset; | 
| 78 |  |  |  |  |  |  | } | 
| 79 |  |  |  |  |  |  | } #foreach arg | 
| 80 | 15 |  |  |  |  | 43 | 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 | 10 | 50 |  | 10 | 1 | 44 | my $self = shift or croak 'Need an instance'; | 
| 93 | 10 |  |  |  |  | 172 | my $lrSourceFiles; | 
| 94 |  |  |  |  |  |  |  | 
| 95 | 10 |  | 100 |  |  | 199 | my $hrSourceFiles = | 
| 96 |  |  |  |  |  |  | $self->scope->find(-name => 'made', -set => '*', -levels => 'local') // {}; | 
| 97 |  |  |  |  |  |  |  | 
| 98 | 10 | 100 |  |  |  | 5721 | if(keys %$hrSourceFiles) { | 
| 99 | 8 |  |  |  |  | 38 | $lrSourceFiles = $hrSourceFiles->{(keys %$hrSourceFiles)[0]}; | 
| 100 |  |  |  |  |  |  | } else { | 
| 101 | 2 |  |  |  |  | 11 | $lrSourceFiles = []; | 
| 102 |  |  |  |  |  |  | } | 
| 103 |  |  |  |  |  |  |  | 
| 104 | 10 | 100 |  |  |  | 33 | return $lrSourceFiles unless wantarray; | 
| 105 | 6 |  |  |  |  | 28 | 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 |  |  |  |  |  |  | my $orig = shift; | 
| 118 |  |  |  |  |  |  | my $self = shift or croak 'Need an instance'; | 
| 119 |  |  |  |  |  |  | my $retval = $self->$orig(@_); | 
| 120 |  |  |  |  |  |  |  | 
| 121 |  |  |  |  |  |  | $retval->{made} = $self->made unless ref $retval->{made} eq 'ARRAY'; | 
| 122 |  |  |  |  |  |  | # TODO clone?  Shallow copy? | 
| 123 |  |  |  |  |  |  | return $retval; | 
| 124 |  |  |  |  |  |  | }; #run() | 
| 125 |  |  |  |  |  |  |  | 
| 126 |  |  |  |  |  |  | 1; | 
| 127 |  |  |  |  |  |  | __END__ | 
| 128 |  |  |  |  |  |  | # vi: set fdm=marker: # |