File Coverage

blib/lib/POE/Component/CSS/Minifier.pm
Criterion Covered Total %
statement 18 38 47.3
branch 0 20 0.0
condition 0 6 0.0
subroutine 6 9 66.6
pod 1 1 100.0
total 25 74 33.7


line stmt bran cond sub pod time code
1             package POE::Component::CSS::Minifier;
2              
3 1     1   304133 use warnings;
  1         3  
  1         42  
4 1     1   5 use strict;
  1         3  
  1         48  
5              
6             our $VERSION = '1.001004'; # VERSION
7              
8 1     1   4 use POE;
  1         2  
  1         9  
9 1     1   404 use base 'POE::Component::NonBlockingWrapper::Base';
  1         2  
  1         95  
10 1     1   12 use CSS::Minifier;
  1         3  
  1         43  
11 1     1   5 use LWP::UserAgent;
  1         1  
  1         465  
12              
13             sub _methods_define {
14 0     0     return ( minify => '_wheel_entry' );
15             }
16              
17             sub minify {
18 0     0 1   $poe_kernel->post( shift->{session_id} => minify => @_ );
19             }
20              
21             sub _process_request {
22 0     0     my ( $self, $in_ref ) = @_;
23              
24 0           eval {
25 0 0         if ( defined $in_ref->{infile} ) {
    0          
26 0 0 0       open my $in, '<', $in_ref->{infile}
27             or $in_ref->{error} = "infile error [$!]"
28             and return;
29              
30              
31 0 0         if ( defined $in_ref->{outfile} ) {
32 0 0 0       open my $out, '>', $in_ref->{outfile}
33             or $in_ref->{error} = "outfile error [$!]"
34             and return;
35              
36 0           CSS::Minifier::minify( input => $in, outfile => $out );
37             }
38             else {
39 0           $in_ref->{out} = CSS::Minifier::minify( input => $in );
40             }
41             }
42             elsif ( $in_ref->{uri} ) {
43 0 0         my $response
44 0           = LWP::UserAgent->new( %{ $self->{ua_args} || {} } )->get( $in_ref->{uri} );
45              
46 0 0         if ( $response->is_success ) {
47 0 0         if ( defined $in_ref->{outfile} ) {
48 0 0 0       open my $out, '>', $in_ref->{outfile}
49             or $in_ref->{error} = "outfile error [$!]"
50             and return;
51              
52 0           CSS::Minifier::minify(
53             input => $response->decoded_content,
54             outfile => $out,
55             );
56             }
57             else {
58 0           $in_ref->{out} = CSS::Minifier::minify( input => $response->decoded_content );
59             }
60             }
61             else {
62 0           $in_ref->{error} = $response->status_line;
63             }
64             }
65             else {
66 0           $in_ref->{out} = CSS::Minifier::minify( input => $in_ref->{in} );
67             }
68             };
69 0 0         $@ and $in_ref->{out} = "ERROR: $@";
70             }
71              
72             1;
73             __END__