Maker.pm

filter: Statementstmt 43.4% 23 / 53 Branchbran 0.0% 0 / 12 Conditioncond 0.0% 0 / 10 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 35.7% 5 / 14 Podpod 20.0% 1 / 5 totaltotal 29.5% 29 / 98 CC 11 SCAR 27.3
CC
11
Cov
31%
make
42.0
find_target
20.0
can_make
6.0
CRAP 15.3
« Maker/FileFinder/Query.pm ↑ Summary Maker/Source/FileScan.pm »
1 package Document::Maker;
2  
3 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 =head1 NAME
7  
8 Document::Maker - Makefile-like functionality in Perl
9  
10 =head1 VERSION
11  
12 Version 0.022
13  
14 =cut
15  
16 1 our $VERSION = '0.022';
17  
18 =head1 SYNOPSIS
19  
20 my $maker = Document::Maker->new;
21  
22 $maker->parser->parse_target( "tgt/a.out" => "src/defs.txt",
23 do => sub {
24 my $target = shift;
25 my $file = shift; # tgt/a.out
26 ....
27 },
28 );
29  
30 $maker->make("tgt/a.out"); # Will only make if "tgt/a.out" is older than "src/defs.txt" or doesn't exist
31  
32 =head1 DESCRIPTION
33  
34 Document::Maker is intended to have similar functionality as GNU make with additional enhancements.
35  
36 WARNING: Although this is a 3rd-iteration attempt at Makefile-ness, the API is very fluid
37 and could change in future versions.
38  
39 WARNING: There may be bugs lurking about, I'll be happy to entertain bug reports.
40  
41 =head2 Already working
42  
43 =head3 Target-from-one-source
44  
45 $maker->parser->parse_target( "tgt/a.out" => "src/defs.txt",
46 do => sub {
47 my $target = shift;
48 my $file = shift; # tgt/a.out
49 ....
50 },
51 );
52  
53 =head3 Target-from-many-sources
54  
55 $maker->parser->parse_target( "tgt/a.out" => [ "src/defs.txt", "src/xyzzy.txt" ],
56 do => sub {
57 my $target = shift;
58 my $file = shift; # tgt/a.out
59 ....
60 },
61 );
62  
63 =head3 Many-targets-dependent-on-many-sources
64  
65 $maker->parser->parse_target( [ "tgt/a.out", "tgt/b.out" ] => [ "src/defs.txt", "src/xyzzy.txt" ],
66 do => sub {
67 my $target = shift;
68 my $file = shift;
69 ....
70 },
71 );
72  
73 =head3 Non-file, Target-only
74  
75 $maker->parser->parse_simple_target( "configure",
76 do => sub {
77 my $target = shift; # No second argument
78 ....
79 },
80 );
81  
82 =head3 Target/source-patterns
83  
84 $maker->parser->parse_pattern_target(qw( tgt/%.html src/%.in a b c d e ), [ "header.html" ], {
85 do => sub {
86 my $target = shift;
87 my $file = shift; # tgt/a.html, tgt/b.html, etc.
88 my $source_file = shift; # src/a.in, src/b.in, etc.
89 ....
90 },
91 });
92  
93 =head3 Target/source-patterns based on crawling through a directory
94  
95 # This will crawl src/ looking for every file matching the src pattern and making a target out of it
96 $maker->parser->parse_pattern_target(qw( tgt/%.html src/%.in src/* ), [ "header.html" ], {
97 do => sub {
98 my $target = shift;
99 my $file = shift;
100 my $source_file = shift;
101 ....
102 },
103 });
104  
105 =head2 Waiting to be implemented
106  
107 =head3 .PHONY targets (always_make flag, sort-of implemented via simple targets)
108  
109 =head3 Control of intermediate targets/sources
110  
111 =head3 Better control of make conditions (should_make parameter)
112  
113 =head3 Shell-like "do" arguments, similar to a real Makefile
114  
115 For example, something like:
116  
117 $maker->parser->parse...(..., do => \<<_END_);
118 @echo "Using m4 first before getting a line count"
119 m4 < main.m4 $< | wc -l > $@
120 _END_
121  
122 =head3 Consistent handling of make failures/stale files
123  
124 =head3 Last-chance wildcard targets
125  
126 =head3 Document and test advanced patterns (embedded regexp, etc.)
127  
128 =head1 AUTHOR
129  
130 Robert Krimen, C<< <rkrimen at cpan.org> >>
131  
132 =head1 BUGS
133  
134 Please report any bugs or feature requests to
135 C<bug-document-maker at rt.cpan.org>, or through the web interface at
136 L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Document-Maker>.
137 I will be notified, and then you'll automatically be notified of progress on
138 your bug as I make changes.
139  
140 =head1 SUPPORT
141  
142 You can find documentation for this module with the perldoc command.
143  
144 perldoc Document::Maker
145  
146 You can also look for information at:
147  
148 =over 4
149  
150 =item * AnnoCPAN: Annotated CPAN documentation
151  
152 L<http://annocpan.org/dist/Document-Maker>
153  
154 =item * CPAN Ratings
155  
156 L<http://cpanratings.perl.org/d/Document-Maker>
157  
158 =item * RT: CPAN's request tracker
159  
160 L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Document-Maker>
161  
162 =item * Search CPAN
163  
164 L<http://search.cpan.org/dist/Document-Maker>
165  
166 =back
167  
168 =head1 ACKNOWLEDGEMENTS
169  
170 =head1 COPYRIGHT & LICENSE
171  
172 Copyright 2007 Robert Krimen, all rights reserved.
173  
174 This program is free software; you can redistribute it and/or modify it
175 under the same terms as Perl itself.
176  
177 =cut
178  
179 1 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
180  
181 1 ▶use Moose::Util::TypeConstraints;
Subroutine BEGIN: called CC=1 SCAR=0.0
182 1 ▶use Path::Class;
Subroutine BEGIN: called CC=1 SCAR=0.0
183  
184 0 ▶type 'Path::Class::File' => where { $_->isa("Path::Class::File") };
Subroutine __ANON__: not called CC=1 SCAR=1.2
185 0 ▶coerce 'Path::Class::File' => from 'Str' => via { Path::Class::File->new($_) };
Subroutine __ANON__: not called CC=1 SCAR=1.2
186  
187 1 with map { "Document::Maker::Role::$_" } qw/Logging/;
188  
189 0 ▶has target_maker_registry => qw/is ro/, default => sub { [] };
Subroutine __ANON__: not called CC=1 SCAR=1.2
190 0 ▶has parser => qw/is ro lazy 1/, default => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
191 0 require Document::Maker::Parser;
192 0 return Document::Maker::Parser->new(maker => shift)
193 1 };
194  
195 0 ▶sub can_make {
Subroutine can_make: not called CC=2 SCAR=17.9
Pod undocumented
196 0 my $self = shift;
197 0 my $name = shift;
198  
199 0 ▶ return 1 if $self->find_target($name);
Branch: 1 branch
BranchTrueFalseTotal
if $self->find_target($name) 0 0 0
200 0 return 0;
201 }
202  
203 0 ▶sub should_make {
Subroutine should_make: not called CC=2 SCAR=17.9
Pod undocumented
204 0 my $self = shift;
205 0 my $name = shift;
206  
207 0 ▶ return 0 unless my $target = $self->find_target($name);
Branch: 1 branch
BranchTrueFalseTotal
unless my $target = $self->find_target($name) 0 0 0
208 0 return $target->should_make;
209 }
210  
211 0 ▶sub make {
Subroutine make: not called CC=6 SCAR=37.4
Pod documented
212 0 my $self = shift;
213 0 for my $name (@_) {
214 0 $self->log->debug("Try to make: $name");
215 0 ▶ $self->log->debug("Couldn't find target to make: $name") and next unless my $target = $self->find_target($name);
Branch: 1 branch
BranchTrueFalseTotal
unless my $target = $self->find_target($name) 0 0 0
Condition0%0/5
(my $target = $self->find_target($name)) || $self->log->debug("Couldn't find target to make: $name") && (next)
l!l&&r!l&&!r
000
$self->log->debug("Couldn't find target to make: $name") and next
!ll
00
MC/DC0%0/2
(my $target = $self->find_target($name)) || $self->log->debug("Couldn't find target to make: $name") && (next)
(my $target = $self->find_target($name)) $self->log->debug("Couldn't find target to make: $name")
Truth table0%0/3
A || B
A= (my $target = $self->find_target($name))B= $self->log->debug("Couldn't find target to make: $name")
ABresult
1X1
011
000
216 0 ▶ $self->log->debug("Shouldn't make: $name") and next unless $target->should_make;
Branch: 1 branch
BranchTrueFalseTotal
unless $target->should_make 0 0 0
Condition0%0/5
$target->should_make || $self->log->debug("Shouldn't make: $name") && (next)
l!l&&r!l&&!r
000
$self->log->debug("Shouldn't make: $name") and next
!ll
00
MC/DC0%0/2
$target->should_make || $self->log->debug("Shouldn't make: $name") && (next)
$target->should_make $self->log->debug("Shouldn't make: $name")
Truth table0%0/3
A || B
A= $target->should_makeB= $self->log->debug("Shouldn't make: $name")
ABresult
1X1
011
000
217 0 $target->make;
218 }
219 }
220  
221 0 ▶sub find_target {
Subroutine find_target: not called CC=4 SCAR=30.0
Pod undocumented
222 0 my $self = shift;
223 0 my $name = shift;
224  
225 0 ▶ return unless my $target_maker_registry = $self->target_maker_registry;
Branch: 1 branch
BranchTrueFalseTotal
unless my $target_maker_registry = $self->target_maker_registry 0 0 0
226 0 my $target;
227 0 for (@$target_maker_registry) {
228 0 ▶ last if $target = $_->can_make($name);
Branch: 1 branch
BranchTrueFalseTotal
if $target = $_->can_make($name) 0 0 0
229 }
230 0 return $target;
231 }
232  
233 0 ▶sub register_target_maker {
Subroutine register_target_maker: not called CC=1 SCAR=6.9
Pod undocumented
234 0 my $self = shift;
235 0 my $target_maker = shift;
236 0 push @{ $self->target_maker_registry }, $target_maker;
237 }
238  
239 1 1; # End of Document::Maker
« Maker/FileFinder/Query.pm ↑ Summary Maker/Source/FileScan.pm »