File Coverage

blib/lib/PYX.pm
Criterion Covered Total %
statement 38 38 100.0
branch 4 4 100.0
condition n/a
subroutine 11 11 100.0
pod 6 6 100.0
total 59 59 100.0


line stmt bran cond sub pod time code
1             package PYX;
2              
3 7     7   75192 use base qw(Exporter);
  7         60  
  7         967  
4 7     7   50 use strict;
  7         13  
  7         148  
5 7     7   30 use warnings;
  7         29  
  7         241  
6              
7 7     7   3399 use PYX::Utils qw(decode);
  7         92081  
  7         143  
8 7     7   641 use Readonly;
  7         13  
  7         2448  
9              
10             # Constants.
11             Readonly::Array our @EXPORT_OK => qw(attribute char comment end_element instruction
12             start_element);
13              
14             our $VERSION = 0.07;
15              
16             # Encode attribute as PYX.
17             sub attribute {
18 2     2 1 5 my (@attr) = @_;
19 2         3 my @ret = ();
20 2         5 while (@attr) {
21 2         5 my ($key, $val) = (shift @attr, shift @attr);
22 2         11 push @ret, "A$key ".decode($val);
23             }
24 2         24 return @ret;
25             }
26              
27             # Encode characters between elements as PYX.
28             sub char {
29 2     2 1 880 my $char = shift;
30 2         9 return '-'.decode($char);
31             }
32              
33             # Encode comment as PYX.
34             sub comment {
35 2     2 1 873 my $comment = shift;
36 2         9 return '_'.decode($comment);
37             }
38              
39             # Encode end of element as PYX.
40             sub end_element {
41 1     1 1 84 my $elem = shift;
42 1         5 return ')'.$elem;
43             }
44              
45             # Encode instruction as PYX.
46             sub instruction {
47 3     3 1 1386 my ($target, $code) = @_;
48 3         11 my $ret = '?'.decode($target);
49 3 100       31 if ($code) {
50 1         6 $ret .= ' '.decode($code);
51             }
52 3         13 return $ret;
53             }
54              
55             # Encode begin of element as PYX.
56             sub start_element {
57 3     3 1 2015 my ($elem, @attr) = @_;
58 3         7 my @ret = ();
59 3         8 push @ret, '('.$elem;
60 3 100       8 if (@attr) {
61 2         5 push @ret, attribute(@attr);
62             }
63 3         10 return @ret;
64             }
65              
66             1;
67              
68             __END__