File Coverage

blib/lib/Tags/Output/PYX.pm
Criterion Covered Total %
statement 58 58 100.0
branch 4 4 100.0
condition n/a
subroutine 14 14 100.0
pod n/a
total 76 76 100.0


line stmt bran cond sub pod time code
1             package Tags::Output::PYX;
2              
3 13     13   131727 use base qw(Tags::Output);
  13         107  
  13         6956  
4 13     13   365140 use strict;
  13         32  
  13         263  
5 13     13   68 use warnings;
  13         26  
  13         353  
6              
7 13     13   67 use Error::Pure qw(err);
  13         27  
  13         499  
8 13     13   72 use Readonly;
  13         25  
  13         492  
9 13     13   6411 use Tags::Utils qw(encode_newline);
  13         95446  
  13         258  
10              
11             # Constants.
12             Readonly::Scalar my $EMPTY_STR => q{};
13             Readonly::Scalar my $SPACE => q{ };
14              
15             our $VERSION = 0.04;
16              
17             # Attributes.
18             sub _put_attribute {
19 9     9   150 my ($self, $attr, $value) = @_;
20 9         24 push @{$self->{'flush_code'}}, "A$attr $value";
  9         29  
21 9         20 return;
22             }
23              
24             # Begin of tag.
25             sub _put_begin_of_tag {
26 22     22   16134 my ($self, $tag) = @_;
27 22         41 push @{$self->{'flush_code'}}, "($tag";
  22         75  
28 22         37 unshift @{$self->{'printed_tags'}}, $tag;
  22         53  
29 22         53 return;
30             }
31              
32             # CData.
33             sub _put_cdata {
34 1     1   189 my ($self, @cdata) = @_;
35 1         5 $self->_put_data(@cdata);
36 1         3 return;
37             }
38              
39             # Comment.
40             sub _put_comment {
41 2     2   210 my ($self, @comments) = @_;
42             $self->_put_data(
43 2         22 map { '' } @comments,
  2         12  
44             );
45 2         4 return;
46             }
47              
48             # Data.
49             sub _put_data {
50 12     12   98 my ($self, @data) = @_;
51 12         35 my $data = join($EMPTY_STR, @data);
52 12         19 push @{$self->{'flush_code'}}, '-'.encode_newline($data);
  12         47  
53 12         127 return;
54             }
55              
56             # End of tag.
57             sub _put_end_of_tag {
58 22     22   1979 my ($self, $tag) = @_;
59 22         62 my $printed = shift @{$self->{'printed_tags'}};
  22         54  
60 22 100       66 if ($printed ne $tag) {
61 1         8 err "Ending bad tag: '$tag' in block of tag '$printed'.";
62             }
63 21         60 push @{$self->{'flush_code'}}, ")$tag";
  21         55  
64 21         48 return;
65             }
66              
67             # Instruction.
68             sub _put_instruction {
69 2     2   210 my ($self, $target, $code) = @_;
70              
71             # Construct instruction line.
72 2         6 my $instruction = '?'.$target;
73 2 100       5 if ($code) {
74 1         2 $instruction .= $SPACE.$code;
75             }
76              
77             # To flush code.
78 2         5 push @{$self->{'flush_code'}}, encode_newline($instruction);
  2         6  
79              
80 2         17 return;
81             }
82              
83             # Raw data.
84             sub _put_raw {
85 1     1   200 my ($self, @raw_data) = @_;
86 1         5 $self->_put_data(@raw_data);
87 1         3 return;
88             }
89              
90             1;
91              
92             __END__