| 1 | 4 | ▶ | use 5.10.0; | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 2 | 4 | ▶ | use strict; | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 3 | 4 | ▶ | use warnings; | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 4 | |||||||||||||||||||||||
| 5 | package Pod::Weaver::Section::Badges::Utils; | ||||||||||||||||||||||
| 6 | |||||||||||||||||||||||
| 7 | # ABSTRACT: Some helpers | ||||||||||||||||||||||
| 8 | 4 | our $AUTHORITY = 'cpan:CSSON'; # AUTHORITY | |||||||||||||||||||||
| 9 | 4 | our $VERSION = '0.0402'; | |||||||||||||||||||||
| 10 | |||||||||||||||||||||||
| 11 | 4 | ▶ | use Moose::Role; | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 12 | 4 | ▶ | use List::Util 'first'; | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 13 | |||||||||||||||||||||||
| 14 | 9 | ▶ | sub get_params_for { | ||||||||||||||||||||
|
Subroutine
get_params_for: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||
| 15 | 9 | my $self = shift; | |||||||||||||||||||||
| 16 | 9 | my $badgename = shift; # Str | |||||||||||||||||||||
| 17 | 9 | my $params = {}; | |||||||||||||||||||||
| 18 | |||||||||||||||||||||||
| 19 | 9 | foreach my $pair ($self->badge_args_kv) { | |||||||||||||||||||||
| 20 | 33 | my($key, $value) = @$pair; | |||||||||||||||||||||
| 21 | |||||||||||||||||||||||
| 22 | # -pluginname_* -> * | ||||||||||||||||||||||
| 23 | 33 | my $key_for_plugin = $key; | |||||||||||||||||||||
| 24 | 33 | $key_for_plugin =~ s{^-${badgename}_}{}; | |||||||||||||||||||||
| 25 | |||||||||||||||||||||||
| 26 | 33 | ▶ | $params->{ $key_for_plugin } = $value if substr($key, 0, 2 + length $badgename) eq sprintf '-%s_' => $badgename; | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 27 | } | ||||||||||||||||||||||
| 28 | 9 | return %{ $params }; | |||||||||||||||||||||
| 29 | } | ||||||||||||||||||||||
| 30 | |||||||||||||||||||||||
| 31 | 9 | ▶ | sub badge_to_class { | ||||||||||||||||||||
|
Subroutine
badge_to_class: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||
| 32 | 9 | my $self = shift; | |||||||||||||||||||||
| 33 | 9 | my $badge_name = shift; # Str | |||||||||||||||||||||
| 34 | 9 | return sprintf 'Badge::Depot::Plugin::%s', ucfirst $badge_name; | |||||||||||||||||||||
| 35 | } | ||||||||||||||||||||||
| 36 | |||||||||||||||||||||||
| 37 | 4 | ▶ | sub create_badges { | ||||||||||||||||||||
|
Subroutine
create_badges: called CC=5 SCAR=16.7
Pod
undocumented
| |||||||||||||||||||||||
| 38 | 4 | my $self = shift; | |||||||||||||||||||||
| 39 | 4 | ▶ | my $badges_args = shift || {}; | ||||||||||||||||||||
|
Condition50%1/2
shift() || {}
MC/DC0%0/1
shift() || {}
shift()
Truth table50%1/2
A
A= shift()
| |||||||||||||||||||||||
| 40 | |||||||||||||||||||||||
| 41 | 4 | my @all_plugins = $self->plugin_searcher->plugins; | |||||||||||||||||||||
| 42 | 4 | my @badge_objects = (); | |||||||||||||||||||||
| 43 | |||||||||||||||||||||||
| 44 | BADGE: | ||||||||||||||||||||||
| 45 | 4 | foreach my $badge ($self->all_badges) { | |||||||||||||||||||||
| 46 | 8 | my $wanted_plugin_class = $self->badge_to_class($badge); | |||||||||||||||||||||
| 47 | 8 | ▶ | my $plugin_class = first { $_ eq $wanted_plugin_class } @all_plugins; | ||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 48 | |||||||||||||||||||||||
| 49 | 8 | ▶ | next BADGE if !defined $plugin_class; | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 50 | 8 | my $plugin = $plugin_class->new($self->get_params_for(lc $badge), %{ $badges_args }); | |||||||||||||||||||||
| 51 | |||||||||||||||||||||||
| 52 | 8 | ▶ | if(!$plugin->DOES('Badge::Depot')) { | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 53 | 0 | warn sprintf '! %s does not consume the Badge::Depot role', $plugin_class; | |||||||||||||||||||||
| 54 | 0 | next BADGE; | |||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||
| 56 | 8 | push @badge_objects => $plugin; | |||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||
| 58 | 4 | return \@badge_objects; # ArrayRef[ ConsumerOf['Badge::Depot'] ] | |||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||
| 60 | |||||||||||||||||||||||
| 61 | 4 | ▶ | sub render_badges { | ||||||||||||||||||||
|
Subroutine
render_badges: called CC=7 SCAR=20.1
Pod
undocumented
| |||||||||||||||||||||||
| 62 | 4 | my $self = shift; | |||||||||||||||||||||
| 63 | 4 | my $format = shift; # Dict[ name => Str, before => Maybe[Str], after => Maybe[Str] ] | |||||||||||||||||||||
| 64 | 4 | my $badges = shift; # ArrayRef[ ConsumerOf['Badge::Depot'] ] | |||||||||||||||||||||
| 65 | |||||||||||||||||||||||
| 66 | 4 | my $pod_command_begin = sprintf '=begin %s', $format->{'name'}; | |||||||||||||||||||||
| 67 | 4 | my $pod_command_end = sprintf '=end %s', $format->{'name'}; | |||||||||||||||||||||
| 68 | 4 | my $format_method = sprintf 'to_%s', $format->{'name'}; | |||||||||||||||||||||
| 69 | |||||||||||||||||||||||
| 70 | 4 | my @badges_output = (); | |||||||||||||||||||||
| 71 | 4 | my @complete_output = (); | |||||||||||||||||||||
| 72 | |||||||||||||||||||||||
| 73 | 4 | ▶ | if($self->find_format(sub { $_ eq $format->{'name'} })) { | ||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.2
Branch: 1 branch
| |||||||||||||||||||||||
| 74 | 4 | ▶ | push @badges_output => grep { defined $_ && length $_ } $_->$format_method foreach (@$badges); | ||||||||||||||||||||
|
Condition33%1/3
defined $_ && length $_
MC/DC0%0/2
defined $_ && length $_
defined $_
length $_
Truth table33%1/3
A && B
A= defined $_B= length $_
| |||||||||||||||||||||||
| 75 | |||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||
| 77 | 4 | ▶ | if(@badges_output) { | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 78 | 4 | push @complete_output => '', $pod_command_begin, '', ; | |||||||||||||||||||||
| 79 | 4 | ▶ | push @complete_output => (($format->{'before'} || ''), join ("\n" => @badges_output), ($format->{'after'} || '')); | ||||||||||||||||||||
|
Condition50%2/4
$format->{'before'} || ''
$format->{'after'} || ''
MC/DC0%0/1
$format->{'before'} || ''
$format->{'before'}
MC/DC0%0/1
$format->{'after'} || ''
$format->{'after'}
Truth table50%1/2
A
A= $format->{'before'}
Truth table50%1/2
A
A= $format->{'after'}
| |||||||||||||||||||||||
| 80 | 4 | push @complete_output => '', $pod_command_end, ''; | |||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||
| 82 | 4 | return \@complete_output; | |||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||
| 84 | |||||||||||||||||||||||
| 85 | |||||||||||||||||||||||
| 86 | 4 | 1; | |||||||||||||||||||||
| 87 | |||||||||||||||||||||||
| 88 | __END__ | ||||||||||||||||||||||