JSAN.pm

filter: Statementstmt 10.9% 18 / 165 Branchbran 0.0% 0 / 54 Conditioncond 0.0% 0 / 9 MC/DCmcdc 0.0% 0 / 5 Subroutinesub 26.3% 5 / 19 Podpod 0.0% 0 / 10 totaltotal 8.7% 23 / 262 CC 38 SCAR 44.8
CC
38
Cov
8%
ACTION_dist
272.0
new
30.0
dist_version
30.0
CRAP 88.5
↑ Summary JSAN/ConfigData.pm »
1 package Module::Build::JSAN;
2  
3 # $Id$
4  
5 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use vars qw($VERSION @ISA);
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 1 $VERSION = '0.05';
9 1 ▶use Module::Build;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 @ISA = qw(Module::Build);
11 1 ▶use File::Spec::Functions qw(catdir catfile);
Subroutine BEGIN: called CC=1 SCAR=0.0
12 1 ▶use File::Basename qw(dirname);
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 0 ▶sub new {
Subroutine new: not called CC=5 SCAR=34.0
Pod undocumented
15 0 my $pkg = shift;
16 0 my %p = @_;
17 0 ▶ $p{metafile} ||= 'META.json';
Condition0%0/2
$p{"metafile"} ||= "META.json"
l!l
00
MC/DC0%0/1
$p{"metafile"} ||= "META.json"
$p{"metafile"}
Truth table0%0/2
A
A= $p{"metafile"}
Aresult
11
00
18 0 ▶ if (my $keywords = delete $p{keywords} || delete $p{tags}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $keywords = delete $p{"keywords"} || delete $p{"tags"}) 0 0 0
Condition0%0/3
delete $p{'keywords'} || delete $p{'tags'}
l!l&&r!l&&!r
000
MC/DC0%0/2
delete $p{'keywords'} || delete $p{'tags'}
delete $p{'keywords'} delete $p{'tags'}
Truth table0%0/3
A || B
A= delete $p{'keywords'}B= delete $p{'tags'}
ABresult
1X1
011
000
19 0 ▶ if ($p{meta_merge}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($p{'meta_merge'}) { } 0 0 0
20 0 $p{meta_merge}->{keywords} = $keywords
21 } else {
22 0 $p{meta_merge} = { keywords => $keywords };
23 }
24 }
25 0 return $pkg->SUPER::new(%p);
26 }
27  
28  
29 0 ▶sub ACTION_dist {
Subroutine ACTION_dist: not called CC=16 SCAR=56.1
Pod undocumented
30 0 my $self = shift;
31  
32 0 require Pod::Simple::HTML;
33 0 require Pod::Simple::Text;
34 0 require Pod::Select;
35  
36 0 for (qw(html text pod)) {
37 0 my $dir = catdir 'doc', $_;
38 0 ▶ unless (-e $dir) {
Branch: 1 branch
BranchTrueFalseTotal
unless (-e $dir) 0 0 0
39 0 ▶ File::Path::mkpath($dir, 0, 0755)
Branch: 1 branch
BranchTrueFalseTotal
File::Path::mkpath($dir, 0, 493) or die "Couldn't mkdir ${dir}: $!" 0 0 0
40 or die "Couldn't mkdir $dir: $!";
41 0 $self->add_to_cleanup($dir);
42 }
43 }
44  
45 0 my $lib_dir = catdir 'lib';
46 0 my $pod_dir = catdir 'doc', 'pod';
47 0 my $html_dir = catdir 'doc', 'html';
48 0 my $txt_dir = catdir 'doc', 'text';
49  
50 0 my $js_files = $self->find_dist_packages;
51 0 foreach my $file (map { $_->{file} } values %$js_files) {
52 0 (my $pod = $file) =~ s|^$lib_dir|$pod_dir|;
53 0 $pod =~ s/\.js$/.pod/;
54 0 my $dir = dirname $pod;
55 0 ▶ unless (-e $dir) {
Branch: 1 branch
BranchTrueFalseTotal
unless (-e $dir) 0 0 0
56 0 ▶ File::Path::mkpath($dir, 0, 0755)
Branch: 1 branch
BranchTrueFalseTotal
File::Path::mkpath($dir, 0, 493) or die "Couldn't mkdir ${dir}: $!" 0 0 0
57 or die "Couldn't mkdir $dir: $!";
58 }
59 # Ignore existing documentation files.
60 0 ▶ next if -e $pod;
Branch: 1 branch
BranchTrueFalseTotal
if -e $pod 0 0 0
61 0 ▶ open my $fh, ">", $pod or die "Cannot open $pod: $!\n";
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, ">", $pod or die "Cannot open ${pod}: $!\n" 0 0 0
62  
63 0 Pod::Select::podselect( { -output => $fh }, $file );
64  
65 0 print $fh "\n=cut\n";
66  
67 0 close $fh;
68 }
69  
70 0 for my $pod (@{Module::Build->rscan_dir($pod_dir, qr/\.pod$/)}) {
71 # Generate HTML docs.
72 0 (my $html = $pod) =~ s|^\Q$pod_dir|$html_dir|;
73 0 $html =~ s/\.pod$/.html/;
74 0 my $dir = dirname $html;
75 0 ▶ unless (-e $dir) {
Branch: 1 branch
BranchTrueFalseTotal
unless (-e $dir) 0 0 0
76 0 ▶ File::Path::mkpath($dir, 0, 0755)
Branch: 1 branch
BranchTrueFalseTotal
File::Path::mkpath($dir, 0, 493) or die "Couldn't mkdir ${dir}: $!" 0 0 0
77 or die "Couldn't mkdir $dir: $!";
78 }
79 0 ▶ open my $fh, ">", $html or die "Cannot open $html: $!\n";
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, ">", $html or die "Cannot open ${html}: $!\n" 0 0 0
80 0 my $parser = Pod::Simple::HTML->new;
81 0 $parser->output_fh($fh);
82 0 $parser->parse_file($pod);
83 0 close $fh;
84  
85 # Generate text docs.
86 0 (my $txt = $pod) =~ s|^\Q$pod_dir|$txt_dir|;
87 0 $txt =~ s/\.pod$/.txt/;
88 0 $dir = dirname $txt;
89 0 ▶ unless (-e $dir) {
Branch: 1 branch
BranchTrueFalseTotal
unless (-e $dir) 0 0 0
90 0 ▶ File::Path::mkpath($dir, 0, 0755)
Branch: 1 branch
BranchTrueFalseTotal
File::Path::mkpath($dir, 0, 493) or die "Couldn't mkdir ${dir}: $!" 0 0 0
91 or die "Couldn't mkdir $dir: $!";
92 }
93 0 ▶ open $fh, ">", $txt or die "Cannot open $txt: $!\n";
Branch: 1 branch
BranchTrueFalseTotal
open $fh, ">", $txt or die "Cannot open ${txt}: $!\n" 0 0 0
94 0 $parser = Pod::Simple::Text->new;
95 0 $parser->output_fh($fh);
96 0 $parser->parse_file($pod);
97 0 close $fh;
98 }
99 0 $self->depends_on('manifest');
100  
101 0 $self->depends_on('distdir');
102  
103 0 my $dist_dir = $self->dist_dir;
104  
105 0 $self->_strip_pod($dist_dir);
106  
107 0 $self->make_tarball($dist_dir);
108 0 $self->delete_filetree($dist_dir);
109  
110  
111 # $self->add_to_cleanup('META.json');
112 # $self->add_to_cleanup('*.gz');
113 }
114  
115 0 ▶sub ACTION_manifest {
Subroutine ACTION_manifest: not called CC=1 SCAR=6.9
Pod undocumented
116 0 my $self = shift;
117 0 $self->SUPER::ACTION_manifest(@_);
118 0 $self->add_to_cleanup('MANIFEST.bak');
119 }
120  
121 0 ▶sub ACTION_deps {
Subroutine ACTION_deps: not called CC=3 SCAR=24.8
Pod undocumented
122 0 my $self = shift;
123  
124 0 my $prefix = './tests/lib';
125  
126 0 require JSAN::Shell;
127 0 my $jsan = JSAN::Shell->new;
128 0 $jsan->index;
129  
130 my @deps = (
131 0 keys( %{$self->{properties}{build_requires}} ),
132 0 keys( %{$self->{properties}{requires}} ),
133 );
134  
135 0 ▶ eval { $jsan->install( $_, $prefix ) }, ($@ && print$@)
Branch: 1 branch
BranchTrueFalseTotal
$@ and print $@ 0 0 0
136 0 for @deps;
137  
138 0 $self->add_to_cleanup( $prefix );
139 }
140  
141 0 ▶sub dist_version {
Subroutine dist_version: not called CC=5 SCAR=34.0
Pod undocumented
142 0 my $self = shift;
143 0 my $p = $self->{properties};
144 0 ▶ return $p->{dist_version} if defined $p->{dist_version};
Branch: 1 branch
BranchTrueFalseTotal
if defined $p->{"dist_version"} 0 0 0
145  
146 0 ▶ if ($self->module_name) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->module_name) 0 0 0
147 $p->{dist_version_from} ||=
148 0 ▶ join( '/', 'lib', split /\./, $self->module_name ) . '.js';
Condition0%0/2
$p->{"dist_version_from"} ||= join("/", "lib", split(/\./, $self->module_name, 0)) . '.js'
l!l
00
MC/DC0%0/1
$p->{"dist_version_from"} ||= join("/", "lib", split(/\./, $self->module_name, 0)) . '.js'
$p->{"dist_version_from"}
Truth table0%0/2
A
A= $p->{"dist_version_from"}
Aresult
11
00
149 0 print $p->{dist_version_from}, $/;
150 }
151  
152 die "Can't determine distribution version, must supply either "
153 . "'dist_version',\n'dist_version_from', or 'module_name' parameter"
154 0 ▶ unless $p->{dist_version_from};
Branch: 1 branch
BranchTrueFalseTotal
unless $p->{"dist_version_from"} 0 0 0
155  
156 # Search for the version number.
157 return $p->{dist_version} = $self->_parse_version(
158 $self->module_name,
159 $p->{dist_version_from}
160 0 );
161 }
162  
163 0 ▶sub find_js_files { shift->_find_file_by_type('js', 'lib') }
Subroutine find_js_files: not called CC=1 SCAR=6.9
Pod undocumented
164  
165 0 ▶sub find_dist_packages {
Subroutine find_dist_packages: not called CC=4 SCAR=30.0
Pod undocumented
166 0 my $self = shift;
167 # Only packages in .js files are candidates for inclusion here.
168 # Only include things in the MANIFEST, not things in developer's
169 # private stock.
170  
171 0 ▶ my $manifest = $self->_read_manifest('MANIFEST')
Branch: 1 branch
BranchTrueFalseTotal
my $manifest = $self->_read_manifest("MANIFEST") or die "Can't find dist packages without a MANIFEST file - run 'manifest' action first" 0 0 0
172 or die "Can't find dist packages without a MANIFEST file "
173 . "- run 'manifest' action first";
174  
175 # Localize
176 0 my %dist_files = map { $self->localize_file_path($_) => $_ }
177 keys %$manifest;
178  
179 0 my @js_files = grep {exists $dist_files{$_}} keys %{ $self->find_js_files };
180  
181 0 my %out;
182 0 for my $file (@js_files) {
183 0 ▶ next if $file =~ m{^t/}; # Skip things in t/
Branch: 1 branch
BranchTrueFalseTotal
if $file =~ m[^t/] 0 0 0
184  
185 # Assume that the file name corresponds to the library. This may need
186 # to be more sophisticated in the future, but will do for now.
187 0 (my $lib = $file) =~ s|^[^/]+/||;
188 0 $lib = join '.', split m{/}, $lib;
189 0 $lib =~ s/\.js$//;
190 $out{$lib} = {
191 0 file => $dist_files{$file},
192 version => $self->_parse_version($lib, $file),
193 };
194 }
195 0 return \%out;
196 }
197  
198 0 ▶sub _parse_version {
Subroutine _parse_version: not called CC=4 SCAR=30.0
199 0 my ($self, $lib, $file) = @_;
200 0 my $version_from = File::Spec->catfile( split m{/}, $file );
201 0 ▶ open VF, "<$version_from" or die "Cannot open '$version_from': $!\n";
Branch: 1 branch
BranchTrueFalseTotal
open VF, "<$version_from" or die "Cannot open '${version_from}': $!\n" 0 0 0
202 0 my $version = '';
203 0 my $find = qr/VERSION\s*(?:=|:)\s*[^\d._]*([\d._]+)/;
204 0 ▶ while (<VF>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline VF)) 0 0 0
205 0 ▶ last if ($version) = /$find/;
Branch: 1 branch
BranchTrueFalseTotal
if ($version) = /$find/ 0 0 0
206 }
207 0 close VF;
208 0 return $version;
209 }
210  
211 0 ▶sub write_metafile {
Subroutine write_metafile: not called CC=3 SCAR=24.8
Pod undocumented
212 0 my $self = shift;
213 0 my $metafile = $self->metafile;
214  
215 0 require Module::Build::JSAN::ConfigData; # Only works after the 'build'
216 0 ▶ if (Module::Build::JSAN::ConfigData->feature('JSON_support')) {
Branch: 1 branch
BranchTrueFalseTotal
if ('Module::Build::JSAN::ConfigData'->feature('JSON_support')) { } 0 0 0
217 0 require JSON;
218 0 $self->prepare_metadata( my $node = {} );
219 0 ▶ open my $meta, '>', $metafile or die "Cannot open '$metafile': $!\n";
Branch: 1 branch
BranchTrueFalseTotal
open my $meta, ">", $metafile or die "Cannot open '${metafile}': $!\n" 0 0 0
220 0 print $meta JSON->new->pretty->encode( $node );
221 0 close $meta;
222 } else {
223 0 $self->log_warn(
224 "\nCouldn't load JSON.pm, generating a minimal META.json without ",
225 "it.\nPlease check and edit the generated metadata, or consider ",
226 "installing\nJSON.pm.\n\n"
227 );
228 0 $self->_write_minimal_metadata;
229 }
230 0 $self->_add_to_manifest('MANIFEST', $metafile);
231 }
232  
233 0 ▶sub _write_minimal_metadata {
Subroutine _write_minimal_metadata: not called CC=2 SCAR=17.9
234 0 my $self = shift;
235 0 my $p = $self->{properties};
236  
237 0 my $file = $self->metafile;
238 0 ▶ my $fh = IO::File->new("> $file") or die "Can't open $file: $!";
Branch: 1 branch
BranchTrueFalseTotal
my $fh = "IO::File"->new("> $file") or die "Can't open ${file}: $!" 0 0 0
239  
240 # XXX Add the meta_add & meta_merge stuff
241 0 print $fh <<"END_OF_META";
242 {
243 "name": "$p->{dist_name}",
244 "version": "$p->{dist_version}",
245 "author":
246 0 @{[ join "\n", map qq{ "$_"}, @{$self->dist_author} ]},
247 0 "abstract": "@{[ $self->dist_abstract ]}",
248 "license": "$p->{license}",
249 "generated_by": "Module::Build::JSAN version $Module::Build::JSAN::VERSION, without JSON.pm"
250 }
251 END_OF_META
252 }
253  
254 0 ▶sub _write_default_maniskip {
Subroutine _write_default_maniskip: not called CC=3 SCAR=24.8
255 0 my $self = shift;
256 0 ▶ my $file = shift || 'MANIFEST.SKIP';
Condition0%0/2
shift() || 'MANIFEST.SKIP'
l!l
00
MC/DC0%0/1
shift() || 'MANIFEST.SKIP'
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
257  
258 0 $self->SUPER::_write_default_maniskip($file);
259  
260 0 ▶ my $fh = IO::File->new(">> $file")
Branch: 1 branch
BranchTrueFalseTotal
my $fh = "IO::File"->new(">> $file") or die "Can't open ${file}: $!" 0 0 0
261 or die "Can't open $file: $!";
262 0 print $fh <<'EOF';
263 ^Build.PL$
264 .tar.gz$
265 ^tests/lib/
266 EOF
267 0 print $fh $self->dist_dir, "\n";
268 0 $fh->close();
269 }
270  
271 0 ▶sub _strip_pod {
Subroutine _strip_pod: not called CC=2 SCAR=17.9
272 0 my ($self, $dist_dir) = @_;
273  
274 0 require Pod::Stripper;
275  
276 0 my $files = $self->find_js_files;
277 0 my $stripper = Pod::Stripper->new;
278 0 foreach my $from ( keys %{$files} ) {
279 0 my $to = catfile $dist_dir, $from;
280 # This will leave empty comment blocks intact.
281 # That looks odd. Pod::Stripper::JSAN should be made.
282 0 chmod 0644, $to;
283 0 $stripper->parse_from_file($from => $to);
284 0 chmod 0444, $to;
285 }
286 }
287  
288 0 ▶sub check_prereq { }
Subroutine check_prereq: not called CC=1 SCAR=0.0
Pod undocumented
289 0 ▶sub ignore_prereqs { 1 }
Subroutine ignore_prereqs: not called CC=1 SCAR=6.9
Pod undocumented
290  
291 1 1;
292 __END__
↑ Summary JSAN/ConfigData.pm »