| 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
| |||||||||||||||||||
| 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
| |||||||||||||||||||
| 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
| |||||||||||||||||||
| 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
MC/DC0%0/1
shift() || 1
shift()
Truth table50%1/2
A
A= shift()
| |||||||||||||||||||
| 53 | |||||||||||||||||||
| 54 | 2 | ▶ | $text = $text->() if eval { ref $text eq 'CODE' }; | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 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
| |||||||||||||||||||
| 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__ | ||||||||||||||||||