Make/File.pm

filter: Statementstmt 96.9% 32 / 33 Branchbran 62.5% 5 / 8 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 10 / 10 Podpod 100% 2 / 2 totaltotal 92.4% 49 / 53 CC 6 SCAR 7.8
CC
6
Cov
90%
make
4.3
_cache_hash
2.1
last_modified
2.0
CRAP 2.2
« Make/DBI/Schema.pm ↑ Summary Make/Cache.pm »
1 package Beam::Make::File;
2 2 our $VERSION = '0.003';
3 # ABSTRACT: A Beam::Make recipe to build a file from shell scripts
4  
5 #pod =head1 SYNOPSIS
6 #pod
7 #pod ### Beamfile
8 #pod a.out:
9 #pod requires:
10 #pod - main.c
11 #pod commands:
12 #pod - cc -Wall main.c
13 #pod
14 #pod =head1 DESCRIPTION
15 #pod
16 #pod This L<Beam::Make> recipe class creates a file by running one or more
17 #pod shell scripts. The recipe's name should be the file that will be created
18 #pod by the recipe.
19 #pod
20 #pod =head1 SEE ALSO
21 #pod
22 #pod L<Beam::Make>, L<Beam::Wire>, L<DBI>
23 #pod
24 #pod =cut
25  
26 2 ▶use v5.20;
Subroutine BEGIN: called CC=1 SCAR=0.0
27 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
28 2 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
29 2 ▶use File::stat;
Subroutine BEGIN: called CC=1 SCAR=0.0
30 2 ▶use Time::Piece;
Subroutine BEGIN: called CC=1 SCAR=0.0
31 2 ▶use Digest::SHA;
Subroutine BEGIN: called CC=1 SCAR=0.0
32 2 ▶use experimental qw( signatures postderef );
Subroutine BEGIN: called CC=1 SCAR=0.0
33  
34 2 extends 'Beam::Make::Recipe';
35  
36 #pod =attr commands
37 #pod
38 #pod An array of commands to run. Commands can be strings, which will be interpreted by
39 #pod the shell, or arrays, which will be invoked directly by the system.
40 #pod
41 #pod # Interpreted as a shell script. Pipes, environment variables, redirects,
42 #pod # etc... allowed
43 #pod - cc -Wall main.c
44 #pod
45 #pod # `cc` invoked directly. Shell functions will not work.
46 #pod - [ cc, -Wall, main.c ]
47 #pod
48 #pod # A single, multi-line shell script
49 #pod - |
50 #pod if [ $( date ) -gt $DATE ]; then
51 #pod echo Another day $( date ) >> /var/log/calendar.log
52 #pod fi
53 #pod
54 #pod =cut
55  
56 2 has commands => ( is => 'ro', required => 1 );
57  
58 5 ▶sub make( $self, %vars ) {
Subroutine make: called CC=4 SCAR=14.6
Pod documented
59 5 for my $cmd ( $self->commands->@* ) {
60 5 ▶ my @cmd = ref $cmd eq 'ARRAY' ? @$cmd : ( $cmd );
Branch: 1 branch
BranchTrueFalseTotal
ref $cmd eq 'ARRAY' ? : 0 5 5
61 5 system @cmd;
62 5 ▶ if ( $? != 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($? != 0) 0 5 5
63 0 die sprintf 'Error running external command "%s": %s', "@cmd", $?;
64 }
65 }
66 # XXX: If the recipe does not create the file, throw an error
67 5 $self->cache->set( $self->name, $self->_cache_hash );
68 5 return 0;
69 }
70  
71 19 ▶sub _cache_hash( $self ) {
Subroutine _cache_hash: called CC=2 SCAR=7.6
72 19 ▶ return -e $self->name ? Digest::SHA->new( 1 )->addfile( $self->name )->b64digest : '';
Branch: 1 branch
BranchTrueFalseTotal
-e $self->name ? : 19 0 19
73 }
74  
75 19 ▶sub last_modified( $self ) {
Subroutine last_modified: called CC=2 SCAR=6.9
Pod documented
76 19 ▶ return -e $self->name ? $self->cache->last_modified( $self->name, $self->_cache_hash ) : 0;
Branch: 1 branch
BranchTrueFalseTotal
-e $self->name ? : 14 5 19
77 }
78  
79 2 1;
80  
81 __END__
« Make/DBI/Schema.pm ↑ Summary Make/Cache.pm »