lib/Dist/Zilla/Plugin/JSAN/Shotenjin.pm

filter: Statementstmt 71.4% 5 / 7 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 3 / 3 Podpod n/a totaltotal 80.0% 8 / 10 CC 1 SCAR 0.9
CC
1
Cov
71%
BEGIN
1.3
BEGIN
1.0
BEGIN
1.0
CRAP 1.1
« lib/Dist/Zilla/Plugin/JSAN/ReadmeFromMD.pm ↑ Summary lib/Dist/Zilla/Plugin/JSAN/GatherDir/Template.pm »
1 package Dist::Zilla::Plugin::JSAN::Shotenjin;
2 2 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
3 2 $Dist::Zilla::Plugin::JSAN::Shotenjin::VERSION = '0.06';
4 }
5  
6 # ABSTRACT: Run the "Shotenjin.Joosed" helper script for the javascript files with templates
7  
8 2 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 0 ▶use Moose::Autobox;
Subroutine BEGIN: called CC=1 SCAR=2.6
10  
11 use Cwd;
12 use Path::Class;
13  
14 use Shotenjin::Embedder;
15  
16 with 'Dist::Zilla::Role::FileMunger';
17  
18  
19 has 'process_list' => (
20 is => 'rw'
21 );
22  
23  
24 sub munge_files {
25 my ($self) = @_;
26
27 for my $file ($self->zilla->files->flatten) {
28
29 foreach my $entry (@{$self->process_list}) {
30
31 if ($file->name =~ $entry->{ regex }) {
32
33 $file->content(
34 Shotenjin::Embedder->process_string(
35 $file->content,
36 $entry->{ keep_whitespace },
37 $entry->{ cwd_as_base } ? cwd() : file($file->name)->dir
38 )
39 )
40 }
41
42 }
43 };
44 }
45  
46  
47 sub BUILDARGS {
48 my ($class, @arg) = @_;
49
50 my %copy = ref $arg[0] ? %{$arg[0]} : @arg;
51  
52 my $zilla = delete $copy{ zilla };
53 my $plugin_name = delete $copy{ plugin_name };
54  
55 my @params;
56  
57 foreach my $entry (keys(%copy)) {
58
59 my %options = map { $_ => 1 } (split m/,/, $copy{ $entry });
60
61 my $keep_whitespace = $options{ kw } || $options{ keep_whitespace };
62 my $cwd_as_base = $options{ absolute } || $options{ cwd_as_base };
63
64 push @params, { regex => qr/$entry/, keep_whitespace => $keep_whitespace, cwd_as_base => $cwd_as_base };
65 }
66
67  
68 return {
69 zilla => $zilla,
70 plugin_name => $plugin_name,
71 process_list => @params > 0 ? \@params : [ { regex => qr/^lib\b/, keep_whitespace => 0, cwd_as_base => 0 } ],
72 }
73 }
74  
75 no Moose;
76 __PACKAGE__->meta->make_immutable();
77  
78  
79 1;
80  
81  
82  
83 __END__
« lib/Dist/Zilla/Plugin/JSAN/ReadmeFromMD.pm ↑ Summary lib/Dist/Zilla/Plugin/JSAN/GatherDir/Template.pm »