blib/lib/Tags/Output/Structure.pm

filter: Statementstmt 87.1% 61 / 70 Branchbran 60.0% 6 / 10 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 15 / 15 Podpod 100% 1 / 1 totaltotal 86.4% 83 / 96 SCAR 19.8
CC
7
Cov
84%
flush
8.5
_put_end_of_tag
2.0
_put_instruction
2.0
CRAP 7.2
↑ Summary
1 package Tags::Output::Structure;
2  
3 9 ▶use base qw(Tags::Output);
Subroutine BEGIN: called CC=1 SCAR=0.0
4 9 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 9 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 9 ▶use Error::Pure qw(err);
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 9 our $VERSION = 0.06;
10  
11 # Flush.
12 sub flush {
13 15 ▶ my ($self, $reset_flag) = @_;
Subroutine flush: called CC=5 SCAR=21.4
Pod documented
14 15 my $ouf = $self->{'output_handler'};
15  
16 # Text output.
17 15 my $ret_ar;
18 15 ▶ if ($ouf) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ouf) { } 0 15 15
19 0 foreach my $line_ar (@{$self->{'flush_code'}}) {
20 0 my $line = "['";
21 0 $line .= join "', '", @{$line_ar};
22 0 $line .= "']".$self->{'output_sep'};
23 9 ▶ no warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
24 0 ▶ print {$ouf} $line
Branch: 1 branch
BranchTrueFalseTotal
print {$ouf;} $line or err("Cannot write to output handler.") 0 0 0
25 or err 'Cannot write to output handler.';
26 }
27  
28 # Structure.
29 } else {
30 15 $ret_ar = $self->{'flush_code'};
31 }
32  
33 # Reset.
34 15 ▶ if ($reset_flag) {
Branch: 1 branch
BranchTrueFalseTotal
if ($reset_flag) 0 15 15
35 0 $self->reset;
36 }
37  
38 15 return $ret_ar;
39 }
40  
41 # Attributes.
42 sub _put_attribute {
43 9 ▶ my ($self, $attr, $value) = @_;
Subroutine _put_attribute: called CC=1 SCAR=0.0
44 9 $self->_put_structure('a', $attr, $value);
45 9 return;
46 }
47  
48 # Begin of tag.
49 sub _put_begin_of_tag {
50 15 ▶ my ($self, $tag) = @_;
Subroutine _put_begin_of_tag: called CC=1 SCAR=0.0
51 15 $self->_put_structure('b', $tag);
52 15 unshift @{$self->{'printed_tags'}}, $tag;
53 15 return;
54 }
55  
56 # CData.
57 sub _put_cdata {
58 1 ▶ my ($self, @cdata) = @_;
Subroutine _put_cdata: called CC=1 SCAR=0.0
59 1 $self->_put_structure('cd', @cdata);
60 1 return;
61 }
62  
63 # Comment.
64 sub _put_comment {
65 2 ▶ my ($self, @comments) = @_;
Subroutine _put_comment: called CC=1 SCAR=0.0
66 2 $self->_put_structure('c', @comments);
67 2 return;
68 }
69  
70 # Data.
71 sub _put_data {
72 6 ▶ my ($self, @data) = @_;
Subroutine _put_data: called CC=1 SCAR=0.0
73 6 $self->_put_structure('d', @data);
74 6 return;
75 }
76  
77 # End of tag.
78 sub _put_end_of_tag {
79 15 ▶ my ($self, $tag) = @_;
Subroutine _put_end_of_tag: called CC=2 SCAR=6.9
80 15 my $printed = shift @{$self->{'printed_tags'}};
81 15 ▶ if ($printed ne $tag) {
Branch: 1 branch
BranchTrueFalseTotal
if ($printed ne $tag) 1 14 15
82 1 err "Ending bad tag: '$tag' in block of tag '$printed'.";
83 }
84 14 $self->_put_structure('e', $tag);
85 14 return;
86 }
87  
88 # Instruction.
89 sub _put_instruction {
90 2 ▶ my ($self, $target, $code) = @_;
Subroutine _put_instruction: called CC=2 SCAR=6.9
91 2 my @instruction = ('i', $target);
92 2 ▶ if ($code) {
Branch: 1 branch
BranchTrueFalseTotal
if ($code) 1 1 2
93 1 push @instruction, $code;
94 }
95 2 $self->_put_structure(@instruction);
96 2 return;
97 }
98  
99 # Raw data.
100 sub _put_raw {
101 1 ▶ my ($self, @raw_data) = @_;
Subroutine _put_raw: called CC=1 SCAR=0.0
102 1 $self->_put_structure('r', @raw_data);
103 1 return;
104 }
105  
106 # Put common structure.
107 sub _put_structure {
108 50 ▶ my ($self, @struct) = @_;
Subroutine _put_structure: called CC=1 SCAR=0.0
109 50 push @{$self->{'flush_code'}}, \@struct;
110 50 return;
111 }
112  
113 9 1;
114  
115 __END__
↑ Summary