ZofCMS/Plugin/Tagged.pm

filter: Statementstmt 26.0% 12 / 46 Branchbran 0.0% 0 / 26 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 50.0% 3 / 6 Podpod 0.0% 0 / 3 totaltotal 18.5% 15 / 81 CC 15 SCAR 47.9
CC
15
Cov
17%
callback
182.0
process
12.0
new
2.0
CRAP 120.3
« ZofCMS/Plugin/AccessDenied.pm ↑ Summary ZofCMS/Plugin/Debug/Validator/HTML.pm »
1 package App::ZofCMS::Plugin::Tagged;
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 Data::Transformer;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 0 ▶sub new { bless {}, shift }
Subroutine new: not called CC=1 SCAR=6.9
Pod undocumented
11  
12 1 my %Tags;
13  
14 0 ▶sub process {
Subroutine process: not called CC=3 SCAR=24.8
Pod undocumented
15 0 my ( $self, $template, $query, $config ) = @_;
16 0 @Tags{ qw/T Q C/ } = (
17 $template,
18 $query,
19 $config->conf,
20 );
21  
22 0 my $opts = delete $template->{tagged_options};
23 0 ▶ $opts = {}
Branch: 1 branch
BranchTrueFalseTotal
unless ref $opts eq "HASH" 0 0 0
24 unless ref $opts eq 'HASH';
25  
26 return
27 0 ▶ if $opts->{no_parse};
Branch: 1 branch
BranchTrueFalseTotal
if $opts->{"no_parse"} 0 0 0
28  
29 0 my $t = Data::Transformer->new( normal => \&callback );
30 0 $t->traverse( $template );
31 }
32  
33 0 ▶sub callback {
Subroutine callback: not called CC=13 SCAR=52.0
Pod undocumented
34 0 my $in = shift;
35  
36 0 ▶ while ( my ( $tag ) = $$in =~ /<TAG:([^>]+)>/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my($tag) = $$in =~ /<TAG:([^>]+)>/) 0 0 0
37 0 ▶ if ( $tag eq 'NOOP' ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($tag eq 'NOOP') { } 0 0 0
elsif ($tag =~ s/^RAND\s*//) { } 0 0 0
38 0 $$in =~ s/<TAG:[^>]+>//;
39 0 return;
40 }
41 elsif ( $tag =~ s/^RAND\s*// ) {
42 0 my $integer_form;
43 0 ▶ if ( $tag =~ s/^I\s*// ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tag =~ s/^I\s*//) 0 0 0
44 0 $integer_form = 1;
45 }
46 0 ▶ my $rand_number = $tag =~ /^[\d.]+$/ ? rand($tag) : rand;
Branch: 1 branch
BranchTrueFalseTotal
$tag =~ /^[\d.]+$/ ? : 0 0 0
47  
48 0 ▶ if ( $integer_form ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($integer_form) 0 0 0
49 0 $rand_number = int $rand_number;
50 }
51  
52 0 $$in =~ s/<TAG:[^>]+>/$rand_number/;
53 }
54  
55 0 my ( $cell, $var ) = split /:/, $tag, 2;
56 0 my $default;
57 0 ▶ if ( length($cell) > 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $cell > 1) 0 0 0
58 0 $default = substr $cell, 1;
59 0 $cell = substr $cell, 0, 1;
60 }
61  
62 0 my $tag_result = $Tags{ $cell };
63  
64 0 my @parts = $var =~ /([{\[]) \s* ( [^}\]]+? ) \s* [}\]]/xg;
65  
66 0 for ( map [splice @parts, 0, 2 ], 0 .. $#parts/2 ) {
67 $tag_result = $_->[0] eq '{'
68 0 ▶ ? $tag_result->{ $_->[1] }
Branch: 1 branch
BranchTrueFalseTotal
$_->[0] eq '{' ? : 0 0 0
69 : $tag_result->[ $_->[1] ]
70 }
71  
72 0 ▶ $tag_result = $default
Branch: 1 branch
BranchTrueFalseTotal
unless defined $tag_result 0 0 0
73 unless defined $tag_result;
74  
75 0 ▶ if ( $@ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
76 0 $Tags{T}{t}{tagged_error} = $@;
77 }
78  
79 0 ▶ $tag_result = '' unless defined $tag_result;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $tag_result 0 0 0
80 0 $$in =~ s/<TAG:[^>]+>/$tag_result/;
81  
82 }
83 }
84  
85 1 1;
86 __END__
« ZofCMS/Plugin/AccessDenied.pm ↑ Summary ZofCMS/Plugin/Debug/Validator/HTML.pm »