TypeCast.pm

filter: Statementstmt 96.5% 56 / 58 Branchbran 62.5% 5 / 8 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 94.1% 16 / 17 Podpod 100% 2 / 2 totaltotal 88.8% 80 / 90 CC 6 SCAR 4.7
CC
6
Cov
90%
_filter
3.2
prepare_app
2.1
call
2.0
CRAP 1.6
↑ Summary TypeCast/EmoticonMap.pm »
1 package Plack::Middleware::UnicodePictogramFallback::TypeCast;
2 2 ▶use 5.008_001;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 2 our $VERSION = '0.02';
8  
9 2 ▶use Plack::Util;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 2 ▶use Plack::Middleware::UnicodePictogramFallback::TypeCast::EmoticonMap;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 2 ▶use Encode qw/encode_utf8 decode/;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 2 ▶use Encode::JP::Mobile ':props';
Subroutine BEGIN: called CC=1 SCAR=0.0
13 2 ▶use Encode::JP::Mobile::UnicodeEmoji;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 2 ▶use parent 'Plack::Middleware';
Subroutine BEGIN: called CC=1 SCAR=0.0
16 2 ▶use Plack::Util::Accessor qw(
Subroutine BEGIN: called CC=1 SCAR=0.0
17 template
18 fallback
19 2 );
20  
21 1 ▶sub prepare_app {
Subroutine prepare_app: called CC=2 SCAR=7.2
Pod documented
22 1 my $self = shift;
23  
24 1 ▶ die 'requires template' unless $self->template;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->template 0 1 1
25 }
26  
27 1 ▶sub call {
Subroutine call: called CC=2 SCAR=6.9
Pod documented
28 1 my ($self, $env) = @_;
29 1 my $res = $self->app->($env);
30  
31 1 my $h = Plack::Util::headers($res->[1]);
32 1 ▶ return $res if $h->get('Content-Type') !~ m!^text/!;
Branch: 1 branch
BranchTrueFalseTotal
unless $h->get("Content-Type") =~ m[^text/] 0 1 1
33  
34 1 ▶ $self->response_cb($res, sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
35 1 my $res = shift;
36 2 ▶ return sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
37 2 my $chunk = shift;
38 2 ▶ return unless defined $chunk;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $chunk 1 1 2
39  
40 1 $self->_filter($chunk);
41 1 };
42 1 });
43 }
44  
45 1 ▶sub _filter {
Subroutine _filter: called CC=3 SCAR=11.7
46 1 my ($self, $html) = @_;
47  
48 1 $html = decode('x-utf8-jp-mobile-unicode-emoji', $html);
49 1 my $emoticon_map = Plack::Middleware::UnicodePictogramFallback::TypeCast::EmoticonMap::MAP;
50  
51 0 ▶ my $fallback = $self->fallback || sub {'〓'};
Subroutine __ANON__: not called CC=1 SCAR=2.0
Condition33%1/3
$self->fallback || sub { "\x{3013}"; }
l!l&&r!l&&!r
010
MC/DC0%0/2
$self->fallback || sub { "\x{3013}"; }
$self->fallback sub { "\x{3013}"; }
Truth table33%1/3
A || B
A= $self->fallbackB= sub { "\x{3013}"; }
ABresult
1X1
011
000
52 1 $html =~ s{(\p{InMobileJPPictograms})}{
53 3 my $char = $1;
54 3 my $code = sprintf '%X', ord $char;
55  
56 3 ▶ if (my $name = $emoticon_map->{$code}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $name = $emoticon_map->{$code}) { } 3 0 3
57 3 sprintf $self->template, $name, $char;
58 } else {
59 0 encode_utf8 $fallback->($char);
60 }
61 }ge;
62  
63 1 encode_utf8 $html;
64 }
65  
66 2 1;
67 __END__
↑ Summary TypeCast/EmoticonMap.pm »