File Coverage

blib/lib/App/PYX2XML.pm
Criterion Covered Total %
statement 45 46 97.8
branch 5 6 83.3
condition 4 6 66.6
subroutine 8 8 100.0
pod 2 2 100.0
total 64 68 94.1


line stmt bran cond sub pod time code
1             package App::PYX2XML;
2              
3 4     4   60614 use strict;
  4         21  
  4         105  
4 4     4   15 use warnings;
  4         7  
  4         78  
5              
6 4     4   6841 use Getopt::Std;
  4         174  
  4         234  
7 4     4   1682 use PYX::SGML::Tags;
  4         203392  
  4         124  
8 4     4   1940 use Tags::Output::Indent;
  4         30820  
  4         115  
9 4     4   29 use Tags::Output::Raw;
  4         5  
  4         1429  
10              
11             our $VERSION = 0.06;
12              
13             # Constructor.
14             sub new {
15 11     11 1 19185 my ($class, @params) = @_;
16              
17             # Create object.
18 11         29 my $self = bless {}, $class;
19              
20             # Object.
21 11         46 return $self;
22             }
23              
24             # Run script.
25             sub run {
26 10     10 1 19 my $self = shift;
27              
28             # Process arguments.
29 10         59 $self->{'_opts'} = {
30             'e' => 'utf-8',
31             'h' => 0,
32             'i' => 0,
33             's' => '',
34             };
35 10 100 66     50 if (! getopts('e:his:', $self->{'_opts'}) || $self->{'_opts'}->{'h'}
      66        
36             || @ARGV < 1) {
37              
38 1         85 print STDERR "Usage: $0 [-e in_enc] [-h] [-i] [-s no_simple] [--version] ".
39             "[filename] [-]\n";
40 1         12 print STDERR "\t-e in_enc\tInput encoding (default value ".
41             "is utf-8)\n";
42 1         10 print STDERR "\t-h\t\tPrint help.\n";
43 1         10 print STDERR "\t-i\t\tIndent output.\n";
44 1         8 print STDERR "\t-s no_simple\tList of element, which cannot be a simple".
45             " like . Separator is comma.\n";
46 1         9 print STDERR "\t--version\tPrint version.\n";
47 1         8 print STDERR "\t[filename]\tProcess on filename\n";
48 1         9 print STDERR "\t[-]\t\tProcess on stdin\n";
49 1         4 return 1;
50             }
51 9         345 $self->{'_filename_or_stdin'} = $ARGV[0];
52              
53             # No simple elements.
54 9         28 my @no_simple = split m/,/ms, $self->{'_opts'}->{'s'};
55              
56             # Tags object.
57 9         15 my $tags;
58 9         38 my %params = (
59             'no_simple' => \@no_simple,
60             'output_handler' => \*STDOUT,
61             'xml' => 1,
62             );
63 9 100       23 if ($self->{'_opts'}->{'i'}) {
64 1         15 $tags = Tags::Output::Indent->new(%params);
65             } else {
66 8         79 $tags = Tags::Output::Raw->new(%params);
67             }
68              
69             # PYX::SGML::Tags object.
70             my $writer = PYX::SGML::Tags->new(
71 9         1442 'input_encoding' => $self->{'_opts'}->{'e'},
72             'tags' => $tags,
73             );
74              
75             # Parse from stdin.
76 9 50       852 if ($self->{'_filename_or_stdin'} eq '-') {
77 0         0 $writer->parse_handler(\*STDIN);
78              
79             # Parse file.
80             } else {
81 9         42 $writer->parse_file($self->{'_filename_or_stdin'});
82             }
83 8         9583 print "\n";
84              
85 8         115 return 0;
86             }
87              
88             1;
89              
90             __END__