Markapl.pm

filter: Statementstmt 98.5% 69 / 70 Branchbran 70.0% 7 / 10 Conditioncond 75.0% 6 / 8 MC/DCmcdc 40.0% 2 / 5 Subroutinesub 100% 19 / 19 Podpod 62.5% 5 / 8 totaltotal 90.0% 108 / 120 CC 11 SCAR 7.6
CC
11
Cov
93%
set
4.1
get
4.0
buffer
3.0
CRAP 2.1
« Markapl/TagHandlers.pm ↑ Summary Markapl/Tags.pm »
1 package Markapl;
2 25 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 28 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 22 ▶use Devel::Declare ();
Subroutine BEGIN: called CC=1 SCAR=0.0
5 22 ▶use Sub::Install qw(install_sub);
Subroutine BEGIN: called CC=1 SCAR=0.0
6 22 ▶use Markapl::Tags;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 22 ▶use Markapl::TagHandlers;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 22 ▶use String::BufferStack;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 22 ▶use HTML::Entities;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 22 ▶use 5.008;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 16 our $VERSION = "0.14";
13  
14 16 my $buffer;
15 457 ▶sub buffer {
Subroutine buffer: called CC=3 SCAR=11.0
Pod undocumented
16 457 ▶ $buffer = $_[1] if $_[1];
Branch: 1 branch
BranchTrueFalseTotal
if $_[1] 4 453 457
17 457 ▶ $buffer ||= String::BufferStack->new( out_method => sub { join("", @_) });
Subroutine __ANON__: called CC=1 SCAR=0.1
Condition66%2/3
$buffer ||= "String::BufferStack"->new("out_method", sub { join "", @_; } )
l!l&&r!l&&!r
436210
MC/DC0%0/2
$buffer ||= "String::BufferStack"->new("out_method", sub { join "", @_; } )
$buffer "String::BufferStack"->new("out_method", sub { join "", @_; } )
Truth table66%2/3
A ||= B
A= $bufferB= "String::BufferStack"->new("out_method", sub { join "", @_; } )
ABresult
1X1
011
000
18 }
19  
20 96 ▶sub template {
Subroutine template: called CC=1 SCAR=0.0
Pod documented
21 96 my ($name, $code) = @_;
22 96 my $caller = caller;
23 96 install_sub({
24 code => $code,
25 into => $caller,
26 as => $name
27 });
28 }
29  
30 12 ▶sub outs_raw($) {
Subroutine outs_raw: called CC=1 SCAR=0.0
Pod undocumented
31 12 my $str = shift;
32 12 Markapl->buffer->append( $str );
33 12 return '';
34 }
35  
36 11 ▶sub outs($) {
Subroutine outs: called CC=1 SCAR=0.0
Pod documented
37 11 my $str = shift;
38 11 outs_raw encode_entities($str, '<>&"');
39 }
40  
41 43 ▶sub render {
Subroutine render: called CC=2 SCAR=6.9
Pod documented
42 43 my ($self, $template, @vars) = @_;
43  
44 43 ▶ if (my $sub = $self->can($template)) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $sub = $self->can($template)) { } 42 1 43
45 42 Markapl->buffer->push;
46 42 $sub->($self, @vars);
47 42 my $buf = Markapl->buffer->pop;
48 42 Markapl->buffer->flush_output;
49 42 return $buf
50 } else {
51 1 require Carp;
52 1 Carp::croak( "no such template: $template in $self" );
53 }
54 }
55  
56 1 ▶sub set {
Subroutine set: called CC=3 SCAR=14.2
Pod documented
57 1 my ($self, $name, $value) = @_;
58  
59 1 ▶ if ($self->can("stash")) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->can('stash')) { } 1 0 1
elsif ((my $caller = caller)->can('stash')) { } 0 0 0
60 1 $self->stash->{$name} = $value;
61 }
62 elsif ((my $caller = caller)->can("stash")) {
63 0 $caller->stash->{$name} = $value;
64 }
65 }
66  
67 5 ▶sub get {
Subroutine get: called CC=4 SCAR=13.9
Pod documented
68 5 my ($self, $name) = @_;
69 5 ▶ if (defined($name) && $self->can("stash")) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $name and $self->can("stash")) 3 2 5
Condition66%2/3
defined $name and $self->can("stash")
!ll&&!rl&&r
203
MC/DC50%1/2
defined $name and $self->can("stash")
defined $name $self->can("stash")
Truth table66%2/3
A and B
A= defined $nameB= $self->can("stash")
ABresult
0X0
100
111
70 3 ▶ return $self->stash->{$name} || ""
Condition100%2/2
$self->stash->{$name} || ''
l!l
21
MC/DC100%1/1
$self->stash->{$name} || ''
$self->stash->{$name}
Truth table100%2/2
A
A= $self->stash->{$name}
Aresult
11
00
71 }
72 2 $name = $self, $self = caller;
73 2 $self->get($name);
74 }
75  
76 29 ▶sub import {
Subroutine import: called CC=3 SCAR=11.0
77 29 my ($class) = @_;
78 29 my $caller = caller;
79  
80 29 for my $name (qw(render outs outs_raw template get set)) {
81 174 install_sub({
82 code => $name,
83 into => $caller,
84 });
85 }
86  
87 29 my $config = {};
88 29 my $code_str = qq{package $caller; my \$stash = {}; sub stash { \$stash } };
89  
90 29 for my $tag ( Markapl::Tags->html() ) {
91 2726 $code_str .= qq{sub $tag (&);};
92 2726 $config->{$tag} = {
93 const => Markapl::TagHandlers::tag_parser_for($tag)
94 }
95 }
96  
97 29 ▶ eval $code_str;
Subroutine stash: called CC=1 SCAR=0.0
Pod undocumented
98  
99 29 Devel::Declare->setup_for($caller, $config);
100 }
101  
102 16 1;
103 __END__
« Markapl/TagHandlers.pm ↑ Summary Markapl/Tags.pm »