blib/lib/Dist/Zilla/Plugin/CSS/Compressor.pm

filter: Statementstmt 97.7% 43 / 44 Branchbran 75.0% 3 / 4 Conditioncond 100% 3 / 3 MC/DCmcdc 100% 2 / 2 Subroutinesub 100% 8 / 8 Podpod 100% 1 / 1 totaltotal 96.7% 60 / 62 CC 5 SCAR 7.1
CC
5
Cov
96%
__ANON__
3.1
gather_files
3.0
BEGIN
1.0
CRAP 2.0
↑ Summary
1 package Dist::Zilla::Plugin::CSS::Compressor;
2  
3 3 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 3 ▶use CSS::Compressor qw( css_compress );
Subroutine BEGIN: called CC=1 SCAR=0.0
5 3 ▶use Dist::Zilla::File::FromCode;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 # ABSTRACT: Compress CSS files
8 3 our $VERSION = '0.02'; # VERSION
9  
10  
11 3 with 'Dist::Zilla::Role::FileGatherer';
12 3 with 'Dist::Zilla::Role::FileInjector';
13  
14 3 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16  
17 3 has finder => (
18 is => 'ro',
19 isa => 'Str',
20 );
21  
22  
23 3 has output_regex => (
24 is => 'ro',
25 isa => 'Str',
26 default => '/\.css$/.min.css/',
27 );
28  
29  
30 3 has output => (
31 is => 'ro',
32 isa => 'Str',
33 );
34  
35  
36 sub gather_files
37 2 ▶{
Subroutine gather_files: called CC=3 SCAR=11.0
Pod documented
38 2 my($self, $arg) = @_;
39
40 2 ▶ my $list = sub {
Subroutine __ANON__: called CC=3 SCAR=11.3
41 defined $self->finder
42 0 ? @{ $self->zilla->find_files($self->finder) }
43 2 ▶ : grep { $_->name =~ /\.css$/ && $_->name !~ /\.min\./ } @{ $self->zilla->files };
Branch: 1 branch
BranchTrueFalseTotal
defined $self->finder ? : 0 2 2
Condition100%3/3
$_->name =~ /\.css$/ && !($_->name =~ /\.min\./)
!ll&&!rl&&r
416
MC/DC100%2/2
$_->name =~ /\.css$/ && !($_->name =~ /\.min\./)
$_->name =~ /\.css$/ !($_->name =~ /\.min\./)
Truth table100%3/3
A && not(B)
A= $_->name =~ /\.css$/B= !($_->name =~ /\.min\./)
ABresult
0X0
100
111
44 2 };
45
46 2 ▶ if(defined $self->output)
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->output) { } 1 1 2
47 {
48 1 my $min_file;
49 $min_file = Dist::Zilla::File::FromCode->new({
50 name => $self->output,
51 1 ▶ code => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
52 1 my @list = $list->();
53 1 $self->log("compressing " . join(', ', map { $_->name } @list) . " => " . $min_file->name);
54 1 css_compress(join("\n", map { $_->content } @list));
55 },
56 1 });
57
58 1 $self->add_file($min_file);
59 }
60 else
61 {
62 1 foreach my $file ($list->()) {
63 3 my $min_file;
64 $min_file = Dist::Zilla::File::FromCode->new({
65 name => do {
66 3 my $min_filename = $file->name;
67 3 eval q{ $min_filename =~ s} . $self->output_regex;
68 3 $min_filename;
69 },
70 3 ▶ code => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
71 3 $self->log("compressing " . $file->name . " => " . $min_file->name);
72 3 css_compress($file->content);
73 },
74 3 });
75
76 3 $self->add_file($min_file);
77 }
78 }
79 }
80  
81 3 __PACKAGE__->meta->make_immutable;
82  
83 3 1;
84  
85 __END__
↑ Summary