tool/generate-mouse-tiny.pl

filter: Statementstmt 100% 56 / 56 Branchbran 62.5% 5 / 8 Conditioncond 95.6% 22 / 23 MC/DCmcdc 88.8% 8 / 9 Subroutinesub 100% 7 / 7 Podpod n/a totaltotal 95.1% 98 / 103 CC 10 SCAR 17.3
CC
10
Cov
95%
__ANON__
9.0
slurp
2.0
BEGIN
1.0
CRAP 5.6
« blib/lib/Mouse/Meta/Method.pm ↑ Summary blib/lib/Mouse/Meta/Attribute.pm »
1 #!/usr/bin/env perl
2 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use File::Find;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use lib ('.', 'lib');
Subroutine BEGIN: called CC=1 SCAR=0.0
6 #use File::Slurp 'slurp';
7 #use List::MoreUtils 'uniq';
8 #use autodie;
9  
10 1 print "Generate Mouse::Tiny ...\n";
11  
12 21 ▶sub slurp {
Subroutine slurp: called CC=2 SCAR=7.1
13 21 ▶ open my $in, '<', $_[0] or die "open $_[0]: $!";
Branch: 1 branch
BranchTrueFalseTotal
open my $in, "<", $_[0] or die "open $_[0]: $!" 21 0 21
14 21 local $/;
15 21 return scalar <$in>;
16 }
17 1 ▶sub uniq{
Subroutine uniq: called CC=1 SCAR=0.0
18 1 my %seen;
19 1 return grep{ !$seen{$_}++ } @_;
20 }
21  
22 1 require Mouse::Spec;
23  
24 1 ▶my $MouseTinyFile = shift || 'lib/Mouse/Tiny.pm';
Condition50%1/2
shift @ARGV || 'lib/Mouse/Tiny.pm'
l!l
10
MC/DC0%0/1
shift @ARGV || 'lib/Mouse/Tiny.pm'
shift @ARGV
Truth table50%1/2
A
A= shift @ARGV
Aresult
11
00
25  
26 1 my @files;
27  
28 find({
29 41 ▶ wanted => sub {
Subroutine __ANON__: called CC=9 SCAR=22.0
30 41 ▶ push @files, $_
Branch: 1 branch
BranchTrueFalseTotal
if -f $_ and /\.pm$/ and not /Squirrel/ and not /Tiny/ and not /Test/ and not /Spec/ and not /TypeRegistry/ and not /\bouse/ 21 20 41
Condition100%21/21
-f $_ and /\.pm$/ and not /Squirrel/ and not /Tiny/ and not /Test/ and not /Spec/ and not /TypeRegistry/ and not /\bouse/
!ll&&!rl&&r
19121
-f $_ and /\.pm$/ and not /Squirrel/ and not /Tiny/ and not /Test/ and not /Spec/ and not /TypeRegistry/
!ll&&!rl&&r
18122
-f $_ and /\.pm$/ and not /Squirrel/ and not /Tiny/ and not /Test/ and not /Spec/
!ll&&!rl&&r
17123
-f $_ and /\.pm$/ and not /Squirrel/ and not /Tiny/ and not /Test/
!ll&&!rl&&r
16124
-f $_ and /\.pm$/ and not /Squirrel/ and not /Tiny/
!ll&&!rl&&r
15125
-f $_ and /\.pm$/ and not /Squirrel/
!ll&&!rl&&r
13226
-f $_ and /\.pm$/
!ll&&!rl&&r
8528
MC/DC100%8/8
-f $_ and /\.pm$/ and not /Squirrel/ and not /Tiny/ and not /Test/ and not /Spec/ and not /TypeRegistry/ and not /\bouse/
-f $_ /\.pm$/ not /Squirrel/ not /Tiny/ not /Test/ not /Spec/ not /TypeRegistry/ not /\bouse/
Truth table100%9/9
A and B and not(C) and not(D) and not(E) and not(F) and not(G) and not(H)
A= -f $_B= /\.pm$/C= not /Squirrel/D= not /Tiny/E= not /Test/F= not /Spec/G= not /TypeRegistry/H= not /\bouse/
ABCDEFGHresult
0XXXXXXX0
10XXXXXX0
110XXXXX0
1110XXXX0
11110XXX0
111110XX0
1111110X0
111111100
111111111
31 if -f $_
32 && /\.pm$/
33 && !/Squirrel/
34 && !/Tiny/
35 && !/Test/ # only for testing
36 && !/Spec/ # has no functionality
37 && !/TypeRegistry/ # deprecated
38 && !/\bouse/ # ouse.pm
39 },
40 1 no_chdir => 1,
41 }, 'lib');
42 1 @files = sort @files;
43  
44 1 my $mouse_tiny = '';
45  
46 1 for my $file (uniq
47 'lib/Mouse/PurePerl.pm',
48 'lib/Mouse/Exporter.pm',
49 'lib/Mouse/Util.pm',
50 'lib/Mouse/Meta/TypeConstraint.pm',
51 'lib/Mouse/Util/TypeConstraints.pm',
52 @files) {
53  
54 21 my $contents = slurp $file;
55  
56 21 $contents =~ s/__END__\b.*//s; # remove documentation
57 21 $contents =~ s/1;\n*$//; # remove success indicator
58  
59 21 $contents =~ s{^( (?:[ ]{4})+ )}{ "\t" x (length($1) / 4) }xmsge; # spaces to tabs
60  
61 21 $mouse_tiny .= "BEGIN{ # $file\n";
62 21 $mouse_tiny .= $contents;
63 21 $mouse_tiny .= "}\n";
64 }
65  
66 1 ▶open my $handle, ">", $MouseTinyFile or die "open $MouseTinyFile: $!";
Branch: 1 branch
BranchTrueFalseTotal
open my $handle, ">", $MouseTinyFile or die "open ${MouseTinyFile}: $!" 1 0 1
67  
68 1 print { $handle } << "EOF";
69 # This file was generated by $0 from Mouse $Mouse::Spec::VERSION.
70 #
71 # ANY CHANGES MADE HERE WILL BE LOST!
72 use strict;
73 use warnings;
74 EOF
75  
76 1 print { $handle } << 'EOF';
77 # if regular Mouse is loaded, bail out
78 unless ($INC{'Mouse.pm'}) {
79 # tell Perl we already have all of the Mouse files loaded:
80 EOF
81  
82 1 for my $file (@files) {
83 21 (my $inc = $file) =~ s{^lib/}{};
84 21 printf { $handle } "%-45s = __FILE__;\n", "\$INC{'$inc'}";
85 }
86  
87 1 print { $handle } << 'EOF';
88 eval sprintf("#line %d %s\n", __LINE__, __FILE__) . <<'END_OF_TINY';
89 EOF
90  
91 1 print { $handle } "\n# and now their contents\n\n";
92  
93 1 print { $handle } $mouse_tiny;
94  
95 1 print { $handle } << 'EOF';
96 END_OF_TINY
97 die $@ if $@;
98 } # unless Mouse.pm is loaded
99 EOF
100  
101 1 print { $handle } << "EOF";
102 package Mouse::Tiny;
103  
104 use version; our \$VERSION = version->declare('$Mouse::Spec::VERSION');
105  
106 Mouse::Exporter->setup_import_methods(also => 'Mouse');
107  
108 1;
109 EOF
110  
111 1 ▶close $handle or die "close $MouseTinyFile: $!";
Branch: 1 branch
BranchTrueFalseTotal
close $handle or die "close ${MouseTinyFile}: $!" 1 0 1
112  
113 1 print "done.\n";
« blib/lib/Mouse/Meta/Method.pm ↑ Summary blib/lib/Mouse/Meta/Attribute.pm »