| 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
| |||||||||||||||
| 24 | unless ref $opts eq 'HASH'; | ||||||||||||||
| 25 | |||||||||||||||
| 26 | return | ||||||||||||||
| 27 | 0 | ▶ | if $opts->{no_parse}; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 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
| |||||||||||||||
| 37 | 0 | ▶ | if ( $tag eq 'NOOP' ) { | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 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
| |||||||||||||||
| 44 | 0 | $integer_form = 1; | |||||||||||||
| 45 | } | ||||||||||||||
| 46 | 0 | ▶ | my $rand_number = $tag =~ /^[\d.]+$/ ? rand($tag) : rand; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 47 | |||||||||||||||
| 48 | 0 | ▶ | if ( $integer_form ) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 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
| |||||||||||||||
| 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
| |||||||||||||||
| 69 | : $tag_result->[ $_->[1] ] | ||||||||||||||
| 70 | } | ||||||||||||||
| 71 | |||||||||||||||
| 72 | 0 | ▶ | $tag_result = $default | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 73 | unless defined $tag_result; | ||||||||||||||
| 74 | |||||||||||||||
| 75 | 0 | ▶ | if ( $@ ) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 76 | 0 | $Tags{T}{t}{tagged_error} = $@; | |||||||||||||
| 77 | } | ||||||||||||||
| 78 | |||||||||||||||
| 79 | 0 | ▶ | $tag_result = '' unless defined $tag_result; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 80 | 0 | $$in =~ s/<TAG:[^>]+>/$tag_result/; | |||||||||||||
| 81 | |||||||||||||||
| 82 | } | ||||||||||||||
| 83 | } | ||||||||||||||
| 84 | |||||||||||||||
| 85 | 1 | 1; | |||||||||||||
| 86 | __END__ | ||||||||||||||