blib/lib/App/TaskBuilder.pm

filter: Statementstmt 44.3% 35 / 79 Branchbran 0.0% 0 / 12 Conditioncond 0.0% 0 / 10 MC/DCmcdc 0.0% 0 / 5 Subroutinesub 63.1% 12 / 19 Podpod 100% 3 / 3 totaltotal 39.0% 50 / 128 CC 14 SCAR 28.2
CC
14
Cov
35%
new
42.0
run
42.0
__ANON__
3.7
CRAP 16.8
↑ Summary
1 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
3  
4 package App::TaskBuilder;
5 1 our $VERSION = '1.000';
6  
7 1 ▶use File::Spec;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use File::Path ();
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use File::Basename ();
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use File::Temp ();
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use File::Copy ();
Subroutine BEGIN: called CC=1 SCAR=0.0
12 1 ▶use Cwd ();
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 5 ▶sub _accessor {
Subroutine _accessor: called CC=1 SCAR=0.5
15 1 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
16 5 my $attr = shift;
17 0 ▶ *$attr = sub { @_ > 1 ? ($_[0]->{$attr} = $_[1]) : $_[0]->{$attr} };
Subroutine __ANON__: not called CC=2 SCAR=13.0
Branch: 1 branch
BranchTrueFalseTotal
@_ > 1 ? : 0 0 0
18 }
19 1 ▶BEGIN { _accessor($_) for qw(name require include version output) }
Subroutine BEGIN: called CC=2 SCAR=6.9
20  
21 0 ▶sub new {
Subroutine new: not called CC=6 SCAR=37.4
Pod documented
22 0 my $class = shift;
23 0 my $self = bless {@_} => $class;
24 0 ▶ $self->{output} ||= $self->vars->{dist_vname} . ".tar.gz";
Condition0%0/2
$self->{"output"} ||= $self->vars->{"dist_vname"} . '.tar.gz'
l!l
00
MC/DC0%0/1
$self->{"output"} ||= $self->vars->{"dist_vname"} . '.tar.gz'
$self->{"output"}
Truth table0%0/2
A
A= $self->{"output"}
Aresult
11
00
25 0 %{ $self->require } = (
26 (map {
27 0 ▶ my %r = %{ do($_) || die $@ };
Condition0%0/2
do $_ || die($@)
l!l
00
MC/DC0%0/1
do $_ || die($@)
do $_
Truth table0%0/2
A
A= do $_
Aresult
11
00
28 (
29 0 ▶ %{ $r{requires} || {} },
Condition0%0/2
$r{'requires'} || {}
l!l
00
MC/DC0%0/1
$r{'requires'} || {}
$r{'requires'}
Truth table0%0/2
A
A= $r{'requires'}
Aresult
11
00
30 0 ▶ %{ $r{test_requires} || {} },
Condition0%0/2
$r{'test_requires'} || {}
l!l
00
MC/DC0%0/1
$r{'test_requires'} || {}
$r{'test_requires'}
Truth table0%0/2
A
A= $r{'test_requires'}
Aresult
11
00
31 0 ▶ %{ $r{build_requires} || {} },
Condition0%0/2
$r{'build_requires'} || {}
l!l
00
MC/DC0%0/1
$r{'build_requires'} || {}
$r{'build_requires'}
Truth table0%0/2
A
A= $r{'build_requires'}
Aresult
11
00
32 );
33 0 } @{ $self->include }),
34 0 %{ $self->require }
35 );
36 0 return $self;
37 }
38  
39 0 ▶sub _dist_name {
Subroutine _dist_name: not called CC=1 SCAR=6.9
40 0 my ($self) = @_;
41 0 (my $name = $self->name) =~ s/::/-/g;
42 0 $name;
43 }
44  
45 0 ▶sub _file_name {
Subroutine _file_name: not called CC=1 SCAR=6.9
46 0 my ($self) = @_;
47 0 my @parts = split /::/, ($self->name . '.pm');
48 0 File::Spec->catfile('lib', @parts);
49 }
50  
51 0 ▶sub vars {
Subroutine vars: not called CC=2 SCAR=12.2
Pod documented
52 0 my $self = shift;
53 1 ▶ use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
54 0 local $Data::Dumper::Terse = 1;
55 0 my %v = (
56 mod_name => $self->name,
57 dist_name => $self->_dist_name,
58 mod_file => $self->_file_name,
59 requires => Dumper($self->require),
60 version => $self->version,
61 );
62 0 $v{dist_vname} = "$v{dist_name}-$v{version}";
63 0 ▶ return wantarray ? %v : \%v;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
64 }
65  
66 0 ▶sub run {
Subroutine run: not called CC=6 SCAR=37.4
Pod documented
67 0 my $self = shift;
68 0 my $old = Cwd::cwd;
69 0 chdir(my $tmp = File::Temp::tempdir(CLEANUP => 1));
70  
71 0 my %v = $self->vars;
72 0 ▶ mkdir $v{dist_vname}, 0755 or die "Can't mkdir $v{dist_vname}: $!";
Branch: 1 branch
BranchTrueFalseTotal
mkdir $v{"dist_vname"}, 493 or die qq[Can't mkdir $v{"dist_vname"}: $!] 0 0 0
73  
74 0 my $s = $self->templates(%v);
75  
76 0 for my $path (keys %$s) {
77 0 my $text = $s->{$path};
78 0 $path = "$v{dist_vname}/$path";
79 0 File::Path::mkpath(File::Basename::dirname($path));
80 0 ▶ open my $fh, '>', $path or die "Can't open $path: $!";
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, ">", $path or die "Can't open ${path}: $!" 0 0 0
81 0 $text =~ s/\{\{(.+?)\}\}/$v{$1}/g;
82 0 print $fh $text;
83 }
84  
85 # XXX use Archive::Tar or something instead
86 0 ▶ system("tar zcf $v{dist_vname}.tar.gz $v{dist_vname}") && exit($? >> 8);
Branch: 1 branch
BranchTrueFalseTotal
system qq[tar zcf $v{"dist_vname"}.tar.gz $v{"dist_vname"}] and exit $? >> 8 0 0 0
87  
88 0 chdir $old;
89 0 ▶ File::Copy::copy "$tmp/$v{dist_vname}.tar.gz", $self->output
Branch: 1 branch
BranchTrueFalseTotal
File::Copy::copy(qq[$tmp/$v{"dist_vname"}.tar.gz], $self->output) or die q[Can't copy to ] . $self->output . ": $!" 0 0 0
90 or die "Can't copy to " . $self->output . ": $!";
91 }
92  
93 0 ▶sub _templates {
Subroutine _templates: not called CC=1 SCAR=6.9
94 0 my ($self, %v) = @_;
95 return {
96 'Makefile.PL' => <<'END',
97 use strict;
98 use warnings;
99 use ExtUtils::MakeMaker;
100 WriteMakefile(
101 NAME => '{{mod_name}}',
102 VERSION_FROM => '{{mod_file}}',
103 ABSTRACT => 'install dependencies for {{mod_name}}',
104 PREREQ_PM => {{requires}},
105 dist => { COMPRESS => 'gzip -9f', SUFFIX => 'gz', },
106 clean => { FILES => '{{dist_name}}-*' },
107 );
108 END
109  
110 'MANIFEST' => <<'END',
111 Makefile.PL
112 README
113 {{mod_file}}
114 END
115  
116 'README' => <<'END',
117 This is an automatically generated README for {{mod_name}}.
118 END
119  
120 $v{mod_file} => <<'END',
121 package
122 {{mod_name}};
123  
124 ${{mod_name}}::VERSION =
125 {{version}};
126  
127 1;
128 END
129  
130 0 };
131 }
132  
133 1 1;
134 __END__
↑ Summary