blib/lib/Mojolicious/Plugin/MostTagHelpers.pm

filter: Statementstmt 90.4% 38 / 42 Branchbran 100% 14 / 14 Conditioncond 50.0% 1 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 87.5% 7 / 8 Podpod 100% 1 / 1 totaltotal 89.7% 61 / 68 CC 10 SCAR 11.9
CC
10
Cov
91%
__ANON__
5.0
_incremental
4.0
register
3.0
CRAP 3.3
↑ Summary
1 package Mojolicious::Plugin::MostTagHelpers;
2  
3 4 ▶use Mojo::Base 'Mojolicious::Plugin';
Subroutine BEGIN: called CC=1 SCAR=0.0
4 4 ▶use HTML::Tagset;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 4 our $VERSION = eval 0.04;
7  
8 4 our %skip = (
9 b => 1, #Mojo::Bytestream
10 c => 1, #Controller
11 title => 1,
12 param => 1,
13 );
14  
15 2 ▶sub register {
Subroutine register: called CC=3 SCAR=11.0
Pod documented
16 2 my ($plugin, $app) = @_;
17 2 foreach my $tag (keys %HTML::Tagset::isKnown) {
18 216 ▶ next if $skip{$tag};
Branch: 1 branch
BranchTrueFalseTotal
if $Mojolicious::Plugin::MostTagHelpers::skip{$tag} 6 210 216
19 210 $app->helper( $tag => _tag($tag) );
20 }
21 2 $app->helper( incremental => \&_incremental );
22 }
23  
24 210 ▶sub _tag {
Subroutine _tag: called CC=1 SCAR=0.0
25 210 my $tag = shift;
26 11 ▶ return sub {
Subroutine __ANON__: called CC=5 SCAR=16.1
27 11 my $self = shift;
28 11 my $id;
29 my @class;
30 11 ▶ if ($_[0] =~ /^[#.]/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_[0] =~ /^[#.]/u) 1 10 11
31 1 my $sel = shift;
32 1 ($id) = $sel =~ /\#([^#. ]+)/;
33 1 @class = $sel =~ /\.([^#. ]+)/g;
34 }
35 return $self->tag(
36 $tag,
37 $id ? ( id => $id ) : (),
38 @class ? ( class => join(' ', @class) ) : (),
39 11 ▶ !$HTML::Tagset::emptyElement{$tag} ? @_ : undef
Branch: 3 branches
BranchTrueFalseTotal
$id ? : 1 10 11
@class ? : 1 10 11
!$HTML::Tagset::emptyElement{$tag} ? : 10 1 11
40 );
41 210 };
42 }
43  
44 0 ▶sub _gen_pod_list {
Subroutine _gen_pod_list: not called CC=1 SCAR=6.9
45 0 my @list = map { "=item $_\n\n" } sort grep { !$skip{$_} } keys %HTML::Tagset::isKnown;
46 0 return '=over', @list, '=back';
47 }
48  
49 2 ▶sub _incremental {
Subroutine _incremental: called CC=4 SCAR=13.9
50 2 my $c = shift;
51 2 my $text = pop;
52 2 ▶ my $i = shift || 1;
Condition50%1/2
shift() || 1
l!l
02
MC/DC0%0/1
shift() || 1
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
53  
54 2 ▶ $text = $text->() if eval { ref $text eq 'CODE' };
Branch: 1 branch
BranchTrueFalseTotal
if eval { do { ref $text eq "CODE" } } 1 1 2
55  
56 2 require Mojo::DOM;
57 2 my $dom = Mojo::DOM->new($text);
58 2 $dom->xml(1);
59 2 my $children = $dom->children;
60 2 ▶ if ($children->size == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($children->size == 1) 1 1 2
61 1 $children = $children->[0]->children;
62 }
63 4 ▶ $children->each(sub{
Subroutine __ANON__: called CC=1 SCAR=0.0
64 4 $_->{ms_overlay} = $i++ . '-';
65 2 });
66  
67 2 require Mojo::ByteStream;
68 2 return Mojo::ByteStream->new($dom->to_string);
69 }
70  
71 4 1;
72  
73 __END__
↑ Summary