blib/lib/Catalyst/View/MobileJpFilter.pm

filter: Statementstmt 83.3% 10 / 12 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 4 / 4 Podpod n/a totaltotal 87.5% 14 / 16 CC 1 SCAR 0.7
CC
1
Cov
83%
BEGIN
1.3
BEGIN
1.0
BEGIN
1.0
CRAP 1.1
↑ Summary
1 package Catalyst::View::MobileJpFilter;
2 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 our $VERSION = '0.01';
5  
6 2 ▶use base 'Catalyst::View';
Subroutine BEGIN: called CC=1 SCAR=0.0
7 0 ▶use Class::C3;
Subroutine BEGIN: called CC=1 SCAR=2.6
8 use Data::Visitor::Callback;
9 use HTML::MobileJp::Filter;
10  
11 __PACKAGE__->mk_accessors(qw( html_filter ));
12  
13 sub new {
14 my ($class, $c, $args) = @_;
15
16 my $self = $class->next::method($c, $args);
17
18 $self->config(
19 $self->merge_config_hashes($self->config, $args)
20 );
21
22 my $v = Data::Visitor::Callback->new(
23 plain_value => sub {
24 return unless defined $_;
25 s{__path_to\((.*?)\)__}{ $c->path_to( $1 ? split( /,/, $1 ) : () ) }eg;
26 },
27 );
28 $v->visit( $self->config );
29
30 $self->html_filter(do {
31 HTML::MobileJp::Filter->new( filters => $self->config->{filters} )
32 });
33
34 $self;
35 }
36  
37 sub render {
38 my ($self, $c) = @_;
39
40 $self->html_filter->filter(
41 mobile_agent => $c->req->mobile_agent,
42 html => $c->res->body || "",
43 );
44 }
45  
46 sub process {
47 my ($self, $c) = @_;
48
49 return 1 if $c->req->method eq 'HEAD';
50 return 1 if $c->res->status =~ /^(?:204|3\d\d)$/;
51 return 1 unless $c->res->body;
52 return 1 unless $c->res->content_type =~ /html$|xhtml\+xml$/;
53  
54 $c->res->body( $self->render($c) );
55  
56 return 1;
57 }
58  
59 1;
60 __END__
↑ Summary