ZofCMS/Plugin/SplitPriceSelect.pm

filter: Statementstmt 34.1% 14 / 41 Branchbran 0.0% 0 / 8 Conditioncond 0.0% 0 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 44.4% 4 / 9 Podpod n/a totaltotal 29.5% 18 / 61 CC 7 SCAR 24.3
CC
7
Cov
27%
_do
20.0
_split_n
20.0
_key
2.0
CRAP 11.3
« ZofCMS/Plugin/AutoEmptyQueryDelete.pm ↑ Summary ZofCMS/Plugin/TOC.pm »
1 package App::ZofCMS::Plugin::SplitPriceSelect;
2  
3 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 1 our $VERSION = '1.001010'; # VERSION
7  
8 1 ▶use base 'App::ZofCMS::Plugin::Base';
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use HTML::Template;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 0 ▶sub _key { 'plug_split_price_select' }
Subroutine _key: not called CC=1 SCAR=6.9
12 0 ▶sub _defaults {
Subroutine _defaults: not called CC=1 SCAR=6.9
13 return (
14 0 t_name => 'plug_split_price_select',
15 # prices => [ qw/foo bar baz/ ],
16 options => 3,
17 name => 'plug_split_price_select',
18 id => 'plug_split_price_select',
19 dollar_sign => 1,
20 );
21 }
22  
23 0 ▶sub _do {
Subroutine _do: not called CC=4 SCAR=30.0
24 0 my ( $self, $conf, $template, $query, $config ) = @_;
25  
26 return
27 0 ▶ unless @{ $conf->{prices} || [] };
Branch: 1 branch
BranchTrueFalseTotal
unless @{$conf->{"prices"} or [];} 0 0 0
Condition0%0/2
$conf->{'prices'} || []
l!l
00
MC/DC0%0/1
$conf->{'prices'} || []
$conf->{'prices'}
Truth table0%0/2
A
A= $conf->{'prices'}
Aresult
11
00
28  
29 0 my @prices = sort { $a <=> $b } @{ $conf->{prices} };
30  
31 0 @prices = _split_n( $conf->{options}, @prices );
32  
33 0 my $t = HTML::Template->new_scalar_ref( \ _html_template() );
34  
35 $t->param(
36 name => $conf->{name},
37 id => $conf->{id},
38 options => [
39 map +{
40 0 value => join('-', @{ $prices[ $_ ] }[0,-1]),
41 name => join ' - ',
42 0 ▶ map { $conf->{dollar_sign} ? "\$$_" : $_ }
Branch: 1 branch
BranchTrueFalseTotal
$conf->{'dollar_sign'} ? : 0 0 0
43 0 @{ $prices[ $_ ] }[0,-1],
44 }, 0 .. $#prices,
45 ],
46 );
47  
48 0 $template->{t}{ $conf->{t_name} } = $t->output;
49 }
50  
51 0 ▶sub _split_n {
Subroutine _split_n: not called CC=4 SCAR=30.0
52 0 my $n = shift;
53 0 ▶ $n = @_ if @_ < $n;
Branch: 1 branch
BranchTrueFalseTotal
if @_ < $n 0 0 0
54 0 my $l = 1 + $#_/$n;
55 0 my @opt = map [splice @_, 0, $l], 1 .. $n;
56  
57 0 for ( reverse 0..$#opt ) {
58 0 ▶ unless( @{ $opt[$_] } ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@{$opt[$_];}) 0 0 0
59 0 push @{ $opt[$_] }, pop @{ $opt[ $_-1 ] }
60 }
61 }
62  
63 return @opt
64 0 }
65  
66  
67 0 ▶sub _html_template {
Subroutine _html_template: not called CC=1 SCAR=6.9
68 0 return <<'END_TEMPLATE';
69 <select id="<tmpl_var escape='html' name='id'>" name="<tmpl_var escape='html' name='name'>"><tmpl_loop name="options">
70 <option value="<tmpl_var escape='html' name='value'>"><tmpl_var escape='html' name='name'></option></tmpl_loop>
71 </select>
72 END_TEMPLATE
73 }
74  
75  
76 1 1;
77 __END__
« ZofCMS/Plugin/AutoEmptyQueryDelete.pm ↑ Summary ZofCMS/Plugin/TOC.pm »