blib/lib/Text/Emoticon.pm

filter: Statementstmt 32.6% 15 / 46 Branchbran 18.7% 3 / 16 Conditioncond 0.0% 0 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 33.3% 3 / 9 Podpod 0.0% 0 / 7 totaltotal 25.9% 21 / 81 CC 10 SCAR 20.2
CC
10
Cov
28%
filter
12.0
do_filter
12.0
new
8.6
CRAP 7.5
↑ Summary
1 package Text::Emoticon;
2  
3 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 our $VERSION = '0.04';
5  
6 2 ▶use UNIVERSAL::require;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 2 my %map;
9  
10 2 ▶sub new {
Subroutine new: called CC=5 SCAR=21.6
Pod undocumented
11 2 my $class = shift;
12 2 ▶ if ($class eq __PACKAGE__) {
Branch: 1 branch
BranchTrueFalseTotal
if ($class eq __PACKAGE__) { } 2 0 2
13 2 my $driver = shift;
14 2 ▶ my $args = @_ == 1 ? $_[0] : {@_};
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 ? : 0 2 2
15  
16 2 my $subclass = "Text::Emoticon::$driver";
17 2 ▶ $subclass->require or die $@;
Branch: 1 branch
BranchTrueFalseTotal
$subclass->require or die $@ 0 2 2
18 0 return bless { %{$subclass->default_config}, %$args }, $subclass;
19 } else {
20 0 ▶ my $args = @_ == 1 ? $_[0] : {@_};
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 ? : 0 0 0
21 0 return bless { %{$class->default_config}, %$args }, $class;
22 }
23 }
24  
25 0 ▶sub register_subclass {
Subroutine register_subclass: not called CC=1 SCAR=6.9
Pod undocumented
26 0 my $class = shift;
27 0 my($map) = @_;
28 0 my $subclass = caller;
29 0 $map{$subclass} = $map;
30 }
31  
32 0 ▶sub map { $map{ref($_[0])} }
Subroutine map: not called CC=1 SCAR=6.9
Pod undocumented
33  
34 0 ▶sub pattern {
Subroutine pattern: not called CC=2 SCAR=17.9
Pod undocumented
35 0 my $self = shift;
36 0 ▶ $self->{re} ||= "(" . join("|", map quotemeta($_), sort { length($b) <=> length($a) } keys %{$self->map}) . ")";
Condition0%0/2
$self->{"re"} ||= '(' . join("|", map(quotemeta($_), (sort {length $b <=> length $a;} keys %{$self->map;}))) . ')'
l!l
00
MC/DC0%0/1
$self->{"re"} ||= '(' . join("|", map(quotemeta($_), (sort {length $b <=> length $a;} keys %{$self->map;}))) . ')'
$self->{"re"}
Truth table0%0/2
A
A= $self->{"re"}
Aresult
11
00
37 0 $self->{re};
38 }
39  
40 0 ▶sub filter_one {
Subroutine filter_one: not called CC=1 SCAR=6.9
Pod undocumented
41 0 my $self = shift;
42 0 my($text) = @_;
43 0 $self->do_filter($self->map->{$text});
44 }
45  
46 0 ▶sub filter {
Subroutine filter: not called CC=3 SCAR=24.8
Pod undocumented
47 0 my($self, $text) = @_;
48 0 ▶ return unless defined $text;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $text 0 0 0
49 0 my $re = $self->pattern;
50 0 ▶ if ($self->{strict}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'strict'}) { } 0 0 0
51 0 $text =~ s{(?<!\w)$re(?!\w)}{$self->do_filter($self->map->{$1})}eg;
52 } else {
53 0 $text =~ s{$re}{$self->do_filter($self->map->{$1})}eg;
54 }
55 0 return $text;
56 }
57  
58 0 ▶sub do_filter {
Subroutine do_filter: not called CC=3 SCAR=24.8
Pod undocumented
59 0 my($self, $icon) = @_;
60 0 ▶ my $class = $self->{class} ? qq( class="$self->{class}") : "";
Branch: 1 branch
BranchTrueFalseTotal
$self->{'class'} ? : 0 0 0
61 0 ▶ my $xhtml = $self->{xhtml} ? qq( /) : "";
Branch: 1 branch
BranchTrueFalseTotal
$self->{'xhtml'} ? : 0 0 0
62  
63 0 return qq(<img src="$self->{imgbase}/$icon"$class$xhtml>);
64 }
65  
66  
67 2 1;
68 __END__
↑ Summary