lib/Mousse/Maker.pm

filter: Statementstmt 0.0% 0 / 69 Branchbran 0.0% 0 / 24 Conditioncond 0.0% 0 / 34 MC/DCmcdc 0.0% 0 / 15 Subroutinesub 0.0% 0 / 7 Podpod 0.0% 0 / 6 totaltotal 0.0% 0 / 155 CC 27 SCAR 39.9
CC
27
Cov
0%
__ANON__
90.0
make_from_mousse
56.0
fixups
56.0
CRAP 54.1
« lib/Mousse.pm ↑ Summary blib/lib/Module/Install/Mousse.pm »
1 package Mousse::Maker;
2 use strict;
3 use warnings;
4  
5 use 5.008003;
6  
7 use Exporter;
8 our @ISA = qw(Exporter);
9 our @EXPORT = qw(make_mousse);
10  
11 our $VERSION = '0.15';
12  
13 sub make_mousse {
14 0 ▶ my $module = shift(@ARGV)
Subroutine make_mousse: not called CC=3 SCAR=24.8
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
my $module = shift @ARGV or die "make_mousse requires a module name argument" 0 0 0
15 or die "make_mousse requires a module name argument";
16 0 ▶ die "'$module' doesn't look like a module name"
Branch: 1 branch
BranchTrueFalseTotal
unless $module =~ /^\w(\w|::)+$/ 0 0 0
17 unless $module =~ /^\w(\w|::)+$/;
18 0 make_from_mousse($module, @ARGV);
19 }
20  
21 sub make_from_mousse {
22 0 ▶ my $Mousse = shift;
Subroutine make_from_mousse: not called CC=7 SCAR=40.3
Pod undocumented
23 0 ▶ my $MousseFile = shift || '';
Condition0%0/2
shift() || ''
l!l
00
MC/DC0%0/1
shift() || ''
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
24 0 require Mousse;
25 0 my $file = $INC{'Mousse.pm'};
26 0 my $contents = slurp($file);
27  
28 0 my $Mousse2 = $Mousse;
29 0 $Mousse2 =~ s/::/\//g;
30  
31 0 ▶ $contents =~ s/Mousse(.)/(($1 eq '\/' or $1 eq '.') ? $Mousse2 : $Mousse) .$1/ge;
Branch: 1 branch
BranchTrueFalseTotal
$1 eq '/' || $1 eq '.' ? : 0 0 0
Condition0%0/3
$1 eq "/" or $1 eq "."
l!l&&r!l&&!r
000
MC/DC0%0/2
$1 eq "/" or $1 eq "."
$1 eq "/" $1 eq "."
Truth table0%0/3
A or B
A= $1 eq "/"B= $1 eq "."
ABresult
1X1
011
000
32 0 my $handle;
33 0 ▶ if ($MousseFile) {
Branch: 1 branch
BranchTrueFalseTotal
if ($MousseFile) { } 0 0 0
34 0 my $MousseDir = $MousseFile;
35 0 ▶ $MousseDir =~ s/(.*[\\\/]).*/$1/ and File::Path::mkpath($MousseDir);
Branch: 1 branch
BranchTrueFalseTotal
$MousseDir =~ s[(.*[\\/]).*][$1] and File::Path::mkpath($MousseDir) 0 0 0
36 0 ▶ open $handle, ">$MousseFile"
Branch: 1 branch
BranchTrueFalseTotal
CORE::open $handle, ">$MousseFile" or die "Can't open $MousseFile for output" 0 0 0
37 or die "Can't open $MousseFile for output";
38 }
39 else {
40 0 $handle = \*STDOUT;
41 }
42  
43 0 print { $handle } $contents;
44 }
45  
46 # This is a modified version of tool/generate-mouse-tiny.pl
47 # from git://git.moose.perl.org/Mouse.git
48 sub make_from_mouse {
49 0 ▶ my $Mousse = shift;
Subroutine make_from_mouse: not called CC=5 SCAR=34.0
Pod undocumented
50 0 ▶ my $MousseFile = shift || '';
Condition0%0/2
shift() || ''
l!l
00
MC/DC0%0/1
shift() || ''
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
51 0 require Mouse;
52 0 my $lib = $INC{'Mouse.pm'};
53 0 $lib =~ s/[\\\/]Mouse\.pm$//;
54  
55 use File::Find;
56 use Fatal qw(open close);
57 use File::Path;
58  
59 sub uniq{
60 0 ▶ my %seen;
Subroutine uniq: not called CC=1 SCAR=6.9
Pod undocumented
61 0 return grep{ !$seen{$_}++ } @_;
62 }
63  
64 0 require "$lib/Mouse/Spec.pm";
65  
66 0 my @files;
67  
68 find({
69 wanted => sub {
70 0 ▶ push @files, $_
Subroutine __ANON__: not called CC=9 SCAR=45.0
Branch: 1 branch
BranchTrueFalseTotal
if -f $_ and /\.pm$/ and /\bMouse\b/ & !/Squirrel/ and not /Tiny/ and not /Test/ and not /Spec/ and not /TypeRegistry/ and not /\bouse/ 0 0 0
Condition0%0/21
-f $_ and /\.pm$/ and /\bMouse\b/ & !/Squirrel/ and not /Tiny/ and not /Test/ and not /Spec/ and not /TypeRegistry/ and not /\bouse/
!ll&&!rl&&r
000
-f $_ and /\.pm$/ and /\bMouse\b/ & !/Squirrel/ and not /Tiny/ and not /Test/ and not /Spec/ and not /TypeRegistry/
!ll&&!rl&&r
000
-f $_ and /\.pm$/ and /\bMouse\b/ & !/Squirrel/ and not /Tiny/ and not /Test/ and not /Spec/
!ll&&!rl&&r
000
-f $_ and /\.pm$/ and /\bMouse\b/ & !/Squirrel/ and not /Tiny/ and not /Test/
!ll&&!rl&&r
000
-f $_ and /\.pm$/ and /\bMouse\b/ & !/Squirrel/ and not /Tiny/
!ll&&!rl&&r
000
-f $_ and /\.pm$/ and /\bMouse\b/ & !/Squirrel/
!ll&&!rl&&r
000
-f $_ and /\.pm$/
!ll&&!rl&&r
000
MC/DC0%0/8
-f $_ and /\.pm$/ and /\bMouse\b/ & !/Squirrel/ and not /Tiny/ and not /Test/ and not /Spec/ and not /TypeRegistry/ and not /\bouse/
-f $_ /\.pm$/ /\bMouse\b/ & !/Squirrel/ not /Tiny/ not /Test/ not /Spec/ not /TypeRegistry/ not /\bouse/
Truth table0%0/9
A and B and C and not(D) and not(E) and not(F) and not(G) and not(H)
A= -f $_B= /\.pm$/C= /\bMouse\b/ & !/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
71 if -f $_
72 && /\.pm$/
73 && /\bMouse\b/
74 & !/Squirrel/
75 && !/Tiny/
76 && !/Test/ # only for testing
77 && !/Spec/ # has no functionality
78 && !/TypeRegistry/ # deprecated
79 && !/\bouse/ # ouse.pm
80 },
81 0 no_chdir => 1,
82 }, $lib);
83  
84 0 my $mousse = '';
85  
86 0 for my $file (uniq
87 "$lib/Mouse/PurePerl.pm",
88 "$lib/Mouse/Exporter.pm",
89 "$lib/Mouse/Util.pm",
90 "$lib/Mouse/Meta/TypeConstraint.pm",
91 "$lib/Mouse/Util/TypeConstraints.pm",
92 sort @files) {
93  
94 0 my $module = $file;
95 0 $module =~ s/^\Q$lib\E\/(.*)\.pm/$1/;
96 0 $module =~ s/\//::/g;
97 0 my $contents = slurp($file);
98  
99 0 fixups($module, \$contents);
100  
101 0 $contents =~ s/__END__\b.*//s; # remove documentation
102 0 $contents =~ s/1;\n*$//; # remove success indicator
103  
104 0 $contents =~ s/Mouse/$Mousse/g;
105  
106 0 $contents =~ s{^( (?:[ ]{4})+ )}{ "\t" x (length($1) / 4) }xmsge; # spaces to tabs
107  
108 0 $mousse .= "# Contents of $module\n";
109 0 $mousse .= $contents;
110 }
111  
112 0 my $handle;
113 0 ▶ if ($MousseFile) {
Branch: 1 branch
BranchTrueFalseTotal
if ($MousseFile) { } 0 0 0
114 0 open $handle, ">$MousseFile";
115 }
116 else {
117 0 $handle = \*STDOUT;
118 }
119  
120 0 print { $handle } << "EOF";
121 # This file was generated by Mousse::Maker $VERSION from Mouse $Mouse::Spec::VERSION.
122 #
123 # ANY CHANGES MADE HERE WILL BE LOST!
124 use strict;
125 use warnings;
126  
127 # tell Perl we already have all of the Mousse files loaded:
128 EOF
129  
130 0 print { $handle } "BEGIN {\n";
131 0 for my $file (@files) {
132 0 $file =~ s/Mouse/$Mousse/g;
133 0 (my $inc = $file) =~ s{^\Q$lib\E/}{};
134 0 printf { $handle } "\t%-45s = __FILE__;\n", "\$INC{'$inc'}";
135 }
136  
137 0 print { $handle } <<"END_OF_MOUSSE";
138 }
139  
140 # and now their contents
141  
142 $mousse;
143  
144 package $Mousse;
145  
146 our \$VERSION = '$Mousse::Maker::VERSION';
147  
148 $Mousse\::Exporter->setup_import_methods(also => '$Mousse\::TOP');
149  
150 1;
151 END_OF_MOUSSE
152  
153 0 close $handle;
154 }
155  
156 sub fixups {
157 0 ▶ my ($module, $contents) = @_;
Subroutine fixups: not called CC=7 SCAR=40.3
Pod undocumented
158 0 ▶ if ($module eq 'Mouse') {
Branch: 2 branches
BranchTrueFalseTotal
if ($module eq 'Mouse') { } 0 0 0
elsif ($module eq 'Mouse::Util' or $module eq 'Mouse::Meta::Module' or $module eq 'Mouse::Meta::Class') { } 0 0 0
159 0 ▶ $$contents =~ s/Mouse/Mouse::TOP/m or die;
Branch: 1 branch
BranchTrueFalseTotal
$$contents =~ s/Mouse/Mouse::TOP/m or die 0 0 0
160 }
161 ▶ elsif (
Condition0%0/6
$module eq "Mouse::Util" or $module eq "Mouse::Meta::Module" or $module eq "Mouse::Meta::Class"
l!l&&r!l&&!r
000
$module eq "Mouse::Util" or $module eq "Mouse::Meta::Module"
l!l&&r!l&&!r
000
MC/DC0%0/3
$module eq "Mouse::Util" or $module eq "Mouse::Meta::Module" or $module eq "Mouse::Meta::Class"
$module eq "Mouse::Util" $module eq "Mouse::Meta::Module" $module eq "Mouse::Meta::Class"
Truth table0%0/4
A or B or C
A= $module eq "Mouse::Util"B= $module eq "Mouse::Meta::Module"C= $module eq "Mouse::Meta::Class"
ABCresult
1XX1
01X1
0011
0000
162 $module eq 'Mouse::Util' or
163 $module eq 'Mouse::Meta::Module' or
164 $module eq 'Mouse::Meta::Class'
165 ) {
166 0 ▶ $$contents =~ s/\n\n/\nno warnings 'once';\n\n/m or die;
Branch: 1 branch
BranchTrueFalseTotal
$$contents =~ s/\n\n/\nno warnings 'once';\n\n/m or die 0 0 0
167 }
168 }
169  
170 sub slurp {
171 0 ▶ open my $in, '<', $_[0];
Subroutine slurp: not called CC=1 SCAR=6.9
Pod undocumented
172 0 local $/;
173 0 return scalar <$in>;
174 }
175  
176 1;
177  
178 =encoding utf-8
179  
180 =head1 NAME
181  
182 Mousse::Maker - Make Your Own Mousse Module
183  
184 =head1 SYNOPSIS
185  
186 In your C<Makefile.PL>:
187  
188 use inc::Module::Install;
189 name 'Chocolate';
190 use_mousse 'Chocolate::Mousse';
191  
192 or (if you don't use Module::Install):
193  
194 perl -MMousse::Maker -e make_mousse 'Chocolate::Mousse' > lib/Chocolate/Mousse.pm
195  
196 =head1 DESCRIPTION
197  
198 Mousse::Maker is the module that Module::Install::Mousse uses to generate your own Mousse OO base class module. You can also use it by hand in a Perl one liner (shown above) if your CPAN module doesn't use Module::Install for its Makefile.PL.
199  
200 =head1 AUTHOR
201  
202 Ingy döt Net <ingy@cpan.org>
203  
204 =head1 COPYRIGHT
205  
206 Copyright (c) 2010, 2011. Ingy döt Net.
207  
208 This program is free software; you can redistribute it and/or modify it
209 under the same terms as Perl itself.
210  
211 See http://www.perl.com/perl/misc/Artistic.html
212  
213 =cut
« lib/Mousse.pm ↑ Summary blib/lib/Module/Install/Mousse.pm »