CatalystX/Starter.pm

filter: Statementstmt 92.1% 70 / 76 Branchbran 50.0% 6 / 12 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 92.3% 12 / 13 Podpod n/a totaltotal 87.1% 88 / 101 CC 10 SCAR 9.9
CC
10
Cov
86%
_fix_files
5.0
_mk_module
4.0
_copy_files
2.0
CRAP 2.7
↑ Summary auto/CatalystX/Starter/t/lib/TestApp.pm »
1 # Copyright (c) 2007 Jonathan Rockway <jrockway@cpan.org>
2  
3 package CatalystX::Starter;
4 6 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 6 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 6 our $VERSION = '0.07';
8  
9 6 ▶use File::ShareDir qw/module_dir/;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 6 ▶use File::Copy::Recursive qw/dircopy/;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 6 ▶use File::Slurp qw/read_file write_file/;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 6 ▶use File::pushd;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 # don't use any of these subroutines.
15  
16 6 ▶sub _boilerplate {
Subroutine _boilerplate: called CC=1 SCAR=0.0
17 6 return module_dir('CatalystX::Starter');
18 }
19  
20 3 ▶sub _module2dist {
Subroutine _module2dist: called CC=2 SCAR=7.0
21 3 my $module = shift;
22 3 ▶ die("You seem to have passed a dist name, not a module name: $module\n")
Branch: 1 branch
BranchTrueFalseTotal
unless $module =~ /::/ 0 3 3
23 unless $module =~ /::/;
24 3 $module =~ s/::/-/g;
25 3 return $module;
26 }
27  
28 3 ▶sub _copy_files {
Subroutine _copy_files: called CC=2 SCAR=7.1
29 3 my $dest = shift;
30 3 my $src = _boilerplate();
31 3 ▶ dircopy($src, $dest) or die "Failed to install boilerplate: $!";
Branch: 1 branch
BranchTrueFalseTotal
dircopy($src, $dest) or die "Failed to install boilerplate: $!" 3 0 3
32 }
33  
34 7 ▶sub _fix_files {
Subroutine _fix_files: called CC=5 SCAR=16.1
35 7 my ($module, $dir) = @_;
36
37 7 ▶ opendir my $dh, $dir or die "Failed to opendir $dir: $!";
Branch: 1 branch
BranchTrueFalseTotal
opendir my $dh, $dir or die "Failed to opendir ${dir}: $!" 7 0 7
38 7 ▶ my @paths = grep {!/^[.][.]?$/} readdir $dh
Branch: 1 branch
BranchTrueFalseTotal
my(@paths) = grep({not /^[.][.]?$/;} readdir $dh) or die "Failed to read ${dir}: $!" 7 0 7
39 or die "Failed to read $dir: $!";
40  
41 7 my $p = pushd $dir;
42 7 my @dirs = grep { -d } @paths;
43 7 my @files = grep { !-d } @paths;
44  
45 # fix files
46 {
47 7 my $dist_name = $module;
48 7 my $main_module_path = "lib/$module.pm";
49 7 $dist_name =~ s/::/-/g;
50 7 $main_module_path =~ s|::|/|g;
51  
52 7 foreach my $file (@files) {
53 15 my $data = read_file($file);
54 15 chmod 0644, $file;
55 15 $data =~ s/\[% DIST_NAME %\]/$dist_name/g;
56 15 $data =~ s/\[% MODULE %\]/$module/g;
57 15 $data =~ s/\[% MAIN_MODULE_PATH %\]/$main_module_path/g;
58 15 write_file($file, $data);
59 }
60 }
61 # fix subdirs
62 7 _fix_files($module, $_) for @dirs;
63 7 closedir $dh;
64
65 7 return;
66 }
67  
68 3 ▶sub _split_module {
Subroutine _split_module: called CC=1 SCAR=0.0
69 3 my $module = shift;
70 3 return split /::/, $module;
71 }
72  
73 1 ▶sub _mk_module {
Subroutine _mk_module: called CC=4 SCAR=13.9
74 1 my $module = shift;
75 1 my $dist = shift;
76
77 1 my $d = pushd $dist;
78 1 mkdir 'lib';
79 1 ▶ die "Failed to create lib in $dist: $!" unless -d 'lib';
Branch: 1 branch
BranchTrueFalseTotal
unless -d "lib" 0 1 1
80  
81 1 chdir 'lib';
82 1 my @path = _split_module($module);
83 1 my $file = pop @path;
84 1 foreach my $part (@path) {
85 1 mkdir $part;
86 1 ▶ die "Failed to mkdir $part: $!" if !-d $part;
Branch: 1 branch
BranchTrueFalseTotal
unless -d $part 0 1 1
87 1 chdir $part;
88 }
89
90 1 my $data = <<"MOD"; # indented to prevent pod parser from parsing it
91 package $module;
92 use Moose;
93 use namespace::autoclean;
94
95 1;
96
97 =head1 NAME
98
99 $module -
100
101 =head1 DESCRIPTION
102
103 =head1 METHODS
104
105 =head1 BUGS
106
107 =head1 AUTHOR
108
109 =head1 COPYRIGHT & LICENSE
110  
111 Copyright 2009 the above author(s).
112
113 This sofware is free software, and is licensed under the same terms as perl itself.
114
115 =cut
116
117 MOD
118
119 1 $data =~ s/^ //mg; # cleanup the leading space
120 1 write_file("$file.pm",$data);
121 1 return;
122 }
123  
124 0 ▶sub _go {
Subroutine _go: not called CC=1 SCAR=6.9
125 0 my $module = shift;
126 0 my $dist = _module2dist($module);
127 0 _copy_files($dist);
128 0 _fix_files($module, $dist);
129 0 _mk_module($module, $dist);
130 0 return $dist;
131 }
132  
133 6 1;
134  
135 __END__
↑ Summary auto/CatalystX/Starter/t/lib/TestApp.pm »