File Coverage

blib/lib/File/Assets/Filter/Minifier/Base.pm
Criterion Covered Total %
statement 24 24 100.0
branch 3 4 75.0
condition 1 3 33.3
subroutine 7 7 100.0
pod 0 1 0.0
total 35 39 89.7


line stmt bran cond sub pod time code
1             package File::Assets::Filter::Minifier::Base;
2              
3 9     9   55 use strict;
  9         15  
  9         418  
4 9     9   47 use warnings;
  9         16  
  9         227  
5              
6 9     9   43 use base qw/File::Assets::Filter::Minifier/;
  9         18  
  9         765  
7 9     9   47 use File::Assets::Carp;
  9         15  
  9         67  
8              
9             my %minifier_package;
10             sub _minifier_package {
11 3     3   12 my $class = shift;
12 3   33     22 return $minifier_package{$class} ||= do {
13 3         9 my $package = substr $class, length qq/File::Assets::Filter::Minifier::/;
14             # JavaScript
15             # JavaScript::XS
16             # CSS
17             # CSS::XS
18 3         13 my @package = split m/::/, $package;
19 3         20 join qw/::/, (shift @package), qw/Minifier/, @package;
20             };
21             }
22              
23             my %minifier_package_is_available;
24             sub _minifier_package_is_available {
25 4     4   7 my $class = shift;
26 4 100       20 return $minifier_package_is_available{$class} if exists $minifier_package_is_available{$class};
27 3         47 my $package = $class->_minifier_package;
28 3         524 return $minifier_package_is_available{$class} = eval "require $package;";
29             }
30              
31             sub new {
32 2     2 0 6 my $class = shift;
33 2 50       16 croak "You need to install ", $class->_minifier_package, " to use this filter: $class" unless $class->_minifier_package_is_available;
34 2         22 return $class->SUPER::new(@_);
35             }
36              
37             1;