File Coverage

blib/lib/Beam/Make/Recipe.pm
Criterion Covered Total %
statement 14 22 63.6
branch 0 2 0.0
condition 0 6 0.0
subroutine 5 6 83.3
pod 1 1 100.0
total 20 37 54.0


line stmt bran cond sub pod time code
1             package Beam::Make::Recipe;
2             our $VERSION = '0.003';
3             # ABSTRACT: The base class for Beam::Make recipes
4              
5             #pod =head1 SYNOPSIS
6             #pod
7             #pod package My::Recipe;
8             #pod use v5.20;
9             #pod use Moo;
10             #pod use experimental qw( signatures );
11             #pod extends 'Beam::Make::Recipe';
12             #pod
13             #pod # Make the recipe
14             #pod sub make( $self ) {
15             #pod ...;
16             #pod }
17             #pod
18             #pod # Return a Time::Piece object for when this recipe was last
19             #pod # performed, or 0 if it can't be determined.
20             #pod sub last_modified( $self ) {
21             #pod ...;
22             #pod }
23             #pod
24             #pod =head1 DESCRIPTION
25             #pod
26             #pod This is the base L<Beam::Make> recipe class. Extend this to build your
27             #pod own recipe components.
28             #pod
29             #pod =head1 REQUIRED METHODS
30             #pod
31             #pod =head2 make
32             #pod
33             #pod This method performs the work of the recipe. There is no return value.
34             #pod
35             #pod =head2 last_modified
36             #pod
37             #pod This method returns a L<Time::Piece> object for when this recipe was last
38             #pod performed, or C<0> otherwise. This method could use the L</cache> object
39             #pod to read a cached date. See L<Beam::Make::Cache> for more information.
40             #pod
41             #pod =head1 SEE ALSO
42             #pod
43             #pod L<Beam::Make>
44             #pod
45             #pod =cut
46              
47 2     2   1019 use v5.20;
  2         13  
48 2     2   14 use warnings;
  2         7  
  2         67  
49 2     2   12 use Moo;
  2         3  
  2         25  
50 2     2   754 use Time::Piece;
  2         4  
  2         12  
51 2     2   172 use experimental qw( signatures postderef );
  2         52  
  2         12  
52              
53             #pod =attr name
54             #pod
55             #pod The name of the recipe. This is the key in the C<Beamfile> used to refer
56             #pod to this recipe.
57             #pod
58             #pod =cut
59              
60             has name => ( is => 'ro', required => 1 );
61              
62             #pod =attr requires
63             #pod
64             #pod An array of recipe names that this recipe depends on.
65             #pod
66             #pod =cut
67              
68             has requires => ( is => 'ro', default => sub { [] } );
69              
70             #pod =attr cache
71             #pod
72             #pod A L<Beam::Make::Cache> object. This is used to store content hashes and
73             #pod modified dates for later use.
74             #pod
75             #pod =cut
76              
77             has cache => ( is => 'ro', required => 1 );
78              
79             #pod =method fill_env
80             #pod
81             #pod Fill in any environment variables in the given array of strings. Environment variables
82             #pod are interpreted as a POSIX shell: C<< $name >> or C<< ${name} >>.
83             #pod
84             #pod =cut
85              
86 0     0 1   sub fill_env( $self, @ary ) {
  0            
  0            
  0            
87             return map {
88 0 0         defined $_ ?
  0            
89 0   0       s{\$\{([^\}]+\})}{ $ENV{ $1 } // ( "\$$1" ) }egr
90 0   0       =~ s{\$([a-zA-Z_][a-zA-Z0-9_]+)}{ $ENV{ $1 } // ( "\$$1" ) }egr
91             : $_
92             } @ary;
93             }
94              
95             1;
96              
97             __END__
98              
99             =pod
100              
101             =head1 NAME
102              
103             Beam::Make::Recipe - The base class for Beam::Make recipes
104              
105             =head1 VERSION
106              
107             version 0.003
108              
109             =head1 SYNOPSIS
110              
111             package My::Recipe;
112             use v5.20;
113             use Moo;
114             use experimental qw( signatures );
115             extends 'Beam::Make::Recipe';
116              
117             # Make the recipe
118             sub make( $self ) {
119             ...;
120             }
121              
122             # Return a Time::Piece object for when this recipe was last
123             # performed, or 0 if it can't be determined.
124             sub last_modified( $self ) {
125             ...;
126             }
127              
128             =head1 DESCRIPTION
129              
130             This is the base L<Beam::Make> recipe class. Extend this to build your
131             own recipe components.
132              
133             =head1 ATTRIBUTES
134              
135             =head2 name
136              
137             The name of the recipe. This is the key in the C<Beamfile> used to refer
138             to this recipe.
139              
140             =head2 requires
141              
142             An array of recipe names that this recipe depends on.
143              
144             =head2 cache
145              
146             A L<Beam::Make::Cache> object. This is used to store content hashes and
147             modified dates for later use.
148              
149             =head1 METHODS
150              
151             =head2 fill_env
152              
153             Fill in any environment variables in the given array of strings. Environment variables
154             are interpreted as a POSIX shell: C<< $name >> or C<< ${name} >>.
155              
156             =head1 REQUIRED METHODS
157              
158             =head2 make
159              
160             This method performs the work of the recipe. There is no return value.
161              
162             =head2 last_modified
163              
164             This method returns a L<Time::Piece> object for when this recipe was last
165             performed, or C<0> otherwise. This method could use the L</cache> object
166             to read a cached date. See L<Beam::Make::Cache> for more information.
167              
168             =head1 SEE ALSO
169              
170             L<Beam::Make>
171              
172             =head1 AUTHOR
173              
174             Doug Bell <preaction@cpan.org>
175              
176             =head1 COPYRIGHT AND LICENSE
177              
178             This software is copyright (c) 2020 by Doug Bell.
179              
180             This is free software; you can redistribute it and/or modify it under
181             the same terms as the Perl 5 programming language system itself.
182              
183             =cut