| 1 | package Tags::Output::PYX; | ||||||||||
| 2 | |||||||||||
| 3 | # Pragmas. | ||||||||||
| 4 | 12 | ▶ | use base qw(Tags::Output); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 12 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 12 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | |||||||||||
| 8 | # Modules. | ||||||||||
| 9 | 12 | ▶ | use Error::Pure qw(err); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | 12 | ▶ | use Readonly; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 11 | 12 | ▶ | use Tags::Utils qw(encode_newline); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 12 | |||||||||||
| 13 | # Constants. | ||||||||||
| 14 | 12 | Readonly::Scalar my $EMPTY_STR => q{}; | |||||||||
| 15 | 12 | Readonly::Scalar my $SPACE => q{ }; | |||||||||
| 16 | |||||||||||
| 17 | # Version. | ||||||||||
| 18 | 12 | our $VERSION = 0.03; | |||||||||
| 19 | |||||||||||
| 20 | # Attributes. | ||||||||||
| 21 | sub _put_attribute { | ||||||||||
| 22 | 9 | ▶ | my ($self, $attr, $value) = @_; | ||||||||
|
Subroutine
_put_attribute: called CC=1 SCAR=0.0
| |||||||||||
| 23 | 9 | push @{$self->{'flush_code'}}, "A$attr $value"; | |||||||||
| 24 | 9 | return; | |||||||||
| 25 | } | ||||||||||
| 26 | |||||||||||
| 27 | # Begin of tag. | ||||||||||
| 28 | sub _put_begin_of_tag { | ||||||||||
| 29 | 20 | ▶ | my ($self, $tag) = @_; | ||||||||
|
Subroutine
_put_begin_of_tag: called CC=1 SCAR=0.0
| |||||||||||
| 30 | 20 | push @{$self->{'flush_code'}}, "($tag"; | |||||||||
| 31 | 20 | unshift @{$self->{'printed_tags'}}, $tag; | |||||||||
| 32 | 20 | return; | |||||||||
| 33 | } | ||||||||||
| 34 | |||||||||||
| 35 | # CData. | ||||||||||
| 36 | sub _put_cdata { | ||||||||||
| 37 | 1 | ▶ | my ($self, @cdata) = @_; | ||||||||
|
Subroutine
_put_cdata: called CC=1 SCAR=0.0
| |||||||||||
| 38 | 1 | $self->_put_data(@cdata); | |||||||||
| 39 | 1 | return; | |||||||||
| 40 | } | ||||||||||
| 41 | |||||||||||
| 42 | # Comment. | ||||||||||
| 43 | sub _put_comment { | ||||||||||
| 44 | 2 | ▶ | my ($self, @comments) = @_; | ||||||||
|
Subroutine
_put_comment: called CC=1 SCAR=0.0
| |||||||||||
| 45 | $self->_put_data( | ||||||||||
| 46 | 2 | map { '<!--'.$_.'-->' } @comments, | |||||||||
| 47 | ); | ||||||||||
| 48 | 2 | return; | |||||||||
| 49 | } | ||||||||||
| 50 | |||||||||||
| 51 | # Data. | ||||||||||
| 52 | sub _put_data { | ||||||||||
| 53 | 12 | ▶ | my ($self, @data) = @_; | ||||||||
|
Subroutine
_put_data: called CC=1 SCAR=0.0
| |||||||||||
| 54 | 12 | my $data = join($EMPTY_STR, @data); | |||||||||
| 55 | 12 | push @{$self->{'flush_code'}}, '-'.encode_newline($data); | |||||||||
| 56 | 12 | return; | |||||||||
| 57 | } | ||||||||||
| 58 | |||||||||||
| 59 | # End of tag. | ||||||||||
| 60 | sub _put_end_of_tag { | ||||||||||
| 61 | 20 | ▶ | my ($self, $tag) = @_; | ||||||||
|
Subroutine
_put_end_of_tag: called CC=2 SCAR=6.9
| |||||||||||
| 62 | 20 | my $printed = shift @{$self->{'printed_tags'}}; | |||||||||
| 63 | 20 | ▶ | if ($printed ne $tag) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 64 | 1 | err "Ending bad tag: '$tag' in block of tag '$printed'."; | |||||||||
| 65 | } | ||||||||||
| 66 | 19 | push @{$self->{'flush_code'}}, ")$tag"; | |||||||||
| 67 | 19 | return; | |||||||||
| 68 | } | ||||||||||
| 69 | |||||||||||
| 70 | # Instruction. | ||||||||||
| 71 | sub _put_instruction { | ||||||||||
| 72 | 2 | ▶ | my ($self, $target, $code) = @_; | ||||||||
|
Subroutine
_put_instruction: called CC=2 SCAR=6.9
| |||||||||||
| 73 | |||||||||||
| 74 | # Construct instruction line. | ||||||||||
| 75 | 2 | my $instruction = '?'.$target; | |||||||||
| 76 | 2 | ▶ | if ($code) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 77 | 1 | $instruction .= $SPACE.$code; | |||||||||
| 78 | } | ||||||||||
| 79 | |||||||||||
| 80 | # To flush code. | ||||||||||
| 81 | 2 | push @{$self->{'flush_code'}}, encode_newline($instruction); | |||||||||
| 82 | |||||||||||
| 83 | 2 | return; | |||||||||
| 84 | } | ||||||||||
| 85 | |||||||||||
| 86 | # Raw data. | ||||||||||
| 87 | sub _put_raw { | ||||||||||
| 88 | 1 | ▶ | my ($self, @raw_data) = @_; | ||||||||
|
Subroutine
_put_raw: called CC=1 SCAR=0.0
| |||||||||||
| 89 | 1 | $self->_put_data(@raw_data); | |||||||||
| 90 | 1 | return; | |||||||||
| 91 | } | ||||||||||
| 92 | |||||||||||
| 93 | 12 | 1; | |||||||||
| 94 | |||||||||||
| 95 | __END__ | ||||||||||