Hopen/G/Runnable.pm

filter: Statementstmt 88.8% 48 / 54 Branchbran 50.0% 4 / 8 Conditioncond 50.0% 4 / 8 MC/DCmcdc 20.0% 1 / 5 Subroutinesub 70.5% 12 / 17 Podpod 100% 2 / 2 totaltotal 75.5% 71 / 94 CC 9 SCAR 11.0
CC
9
Cov
80%
passthrough
6.3
run
4.7
__ANON__
2.0
CRAP 3.0
« Hopen/Scope/Environment.pm ↑ Summary Hopen/Util/Filename.pm »
1 # Build::Hopen::G::Runnable - parent class for anything runnable in a hopen graph
2 package Build::Hopen::G::Runnable;
3 7 ▶use Build::Hopen::Base;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 7 ▶use Build::Hopen;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 7 our $VERSION = '0.000008'; # TRIAL
7  
8 7 ▶use Build::Hopen::Scope::Hash;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 7 ▶use Build::Hopen::Util::Data qw(forward_opts);
Subroutine BEGIN: called CC=1 SCAR=0.0
10 7 ▶use Build::Hopen::Util::NameSet;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 7 ▶use Build::Hopen::Arrrgs;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 7 ▶use Hash::Merge;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 # Docs {{{1
15  
16 =head1 NAME
17  
18 Build::Hopen::G::Runnable - parent class for runnable things in a hopen graph
19  
20 =head1 SYNOPSIS
21  
22 Anything with L</run> inherits from this. TODO should this be a role?
23  
24 =head1 ATTRIBUTES
25  
26 =head2 need
27  
28 Inputs this Runnable requires.
29 A L<Build::Hopen::Util::NameSet>, with the restriction that C<need> may not
30 contain regexes. ("Sorry, I can't run unless you give me every variable
31 in the world that starts with Q." I don't think so!)
32  
33 =head2 scope
34  
35 If defined, a L<Build::Hopen::Scope> that will have the final say on the
36 data used by L</run>. This is the basis of the fine-grained override
37 mechanism in hopen.
38  
39 =head2 want
40  
41 Inputs this Runnable accepts but does not require.
42 A L<Build::Hopen::Util::NameSet>, which may include regexes.
43  
44 =cut
45  
46 # }}}1
47  
48 7 ▶use parent 'Build::Hopen::G::Entity';
Subroutine BEGIN: called CC=1 SCAR=0.0
49 7 ▶use Class::Tiny {
Subroutine BEGIN: called CC=1 SCAR=0.4
50 # NOTE: want and need are not currently used.
51 0 ▶ want => sub { Build::Hopen::Util::NameSet->new },
Subroutine __ANON__: not called CC=1 SCAR=6.9
52 0 ▶ need => sub { Build::Hopen::Util::NameSet->new },
Subroutine __ANON__: not called CC=1 SCAR=6.9
53  
54 6 ▶ scope => sub { Build::Hopen::Scope::Hash->new },
Subroutine __ANON__: called CC=1 SCAR=0.0
55 7 };
56  
57 =head1 FUNCTIONS
58  
59 =head2 run
60  
61 Run the operation, whatever that means. Returns a new hashref.
62 Usage:
63  
64 my $hrOutputs = $op->run([options])
65  
66 Options are:
67  
68 =over
69  
70 =item -context
71  
72 A L<Build::Hopen::Scope> or subclass including the inputs the caller wants to
73 pass to the Runnable. The L</scope> of the Runnable itself may override
74 values in the C<context>.
75  
76 =item -phase
77  
78 If given, the phase that is currently under way in a build-system run.
79  
80 =item -generator
81  
82 If given, the L<Build::Hopen::Gen> instance in use for the current
83 build-system run.
84  
85 =item -nocontext
86  
87 If C<< -nocontext=>1 >> is specified, don't link a context scope into
88 this one. May not be specified together with C<-context>.
89  
90 =back
91  
92 See the source for this function, which contains as an example of setting the
93 scope.
94  
95 =cut
96  
97 9 ▶sub run {
Subroutine run: called CC=4 SCAR=15.5
Pod documented
98 9 my ($self, %args) = parameters('self', [qw(; context phase generator nocontext)], @_);
99 9 my $context_scope = $args{context}; # which may be undef - that's OK
100 9 ▶ croak "Can't combine -context and -nocontext" if $args{context} && $args{nocontext};
Branch: 1 branch
BranchTrueFalseTotal
if $args{"context"} and $args{"nocontext"} 0 9 9
Condition33%1/3
$args{"context"} and $args{"nocontext"}
!ll&&!rl&&r
090
MC/DC0%0/2
$args{"context"} and $args{"nocontext"}
$args{"context"} $args{"nocontext"}
Truth table33%1/3
A and B
A= $args{"context"}B= $args{"nocontext"}
ABresult
0X0
100
111
101  
102 # Link the outer scope to our scope
103 9 ▶ my $saver = $args{nocontext} ? undef : $self->scope->outerize($context_scope);
Branch: 1 branch
BranchTrueFalseTotal
$args{'nocontext'} ? : 0 9 9
104  
105 0 ▶ hlog { ref($self), $self->name, 'input', Dumper($self->scope->as_hashref) } 3;
Subroutine __ANON__: not called CC=1 SCAR=1.2
106  
107 9 my $retval = $self->_run(forward_opts(\%args, {'-'=>1}, qw[phase generator]));
108  
109 0 ▶ hlog { ref $self, $self->name, 'output', Dumper($retval) } 3;
Subroutine __ANON__: not called CC=1 SCAR=1.2
110  
111 9 return $retval;
112 } #run()
113  
114 =head2 _run
115  
116 The internal method that implements L</run>. Must be implemented by
117 subclasses. When C<_run> is called, C<< $self->scope >> has been hooked
118 to the context scope, if any.
119  
120 Parameters are C<-phase> and C<-generator>. C<_run> is always called in scalar
121 context, and must return a new hashref.
122  
123 =cut
124  
125 0 ▶sub _run {
Subroutine _run: not called CC=1 SCAR=6.9
126 0 my ($self, %args) = parameters('self', [qw(; phase generator)], @_);
127 ...
128 0 }
129  
130 =head2 passthrough
131  
132 Returns a new hashref of this Runnable's local values, as defined
133 by L<Build::Hopen::Scope/local>. Usage:
134  
135 my $hashref = $runnable->passthrough([-context => $outer_scope]);
136 # To use $outer_scope as the context
137 my $hashref = $runnable->passthrough(-nocontext => 1);
138 # To leave the context untouched
139  
140 Other valid options include L<-levels|Build::Hopen::Scope/$levels>.
141  
142 =cut
143  
144 8 ▶sub passthrough {
Subroutine passthrough: called CC=6 SCAR=18.5
Pod documented
145 8 my ($self, %args) = parameters('self', ['*'], @_);
146 8 my $outer_scope = $args{context}; # which may be undef - that's OK
147 8 ▶ croak "Can't combine -context and -nocontext" if $args{context} && $args{nocontext};
Branch: 1 branch
BranchTrueFalseTotal
if $args{"context"} and $args{"nocontext"} 0 8 8
Condition33%1/3
$args{"context"} and $args{"nocontext"}
!ll&&!rl&&r
800
MC/DC0%0/2
$args{"context"} and $args{"nocontext"}
$args{"context"} $args{"nocontext"}
Truth table33%1/3
A and B
A= $args{"context"}B= $args{"nocontext"}
ABresult
0X0
100
111
148  
149 # Link the outer scope to our scope
150 8 ▶ my $saver = $args{nocontext} ? undef : $self->scope->outerize($outer_scope);
Branch: 1 branch
BranchTrueFalseTotal
$args{'nocontext'} ? : 8 0 8
151  
152 # Copy the names
153 8 ▶ my $levels = $args{levels} // 'local';
Condition100%2/2
$args{"levels"} // "local"
l!l
71
MC/DC100%1/1
$args{"levels"} // "local"
$args{"levels"}
Truth table100%2/2
A
A= $args{"levels"}
Aresult
11
00
154 8 my @names = @{$self->scope->names(-levels=>$levels)};
155 8 my $retval = {};
156 8 $retval->{$_} = $self->scope->find($_, -levels=>$levels) foreach @names;
157  
158 8 return $retval;
159 } #passthrough()
160  
161 7 1;
162 __END__
« Hopen/Scope/Environment.pm ↑ Summary Hopen/Util/Filename.pm »