File Coverage

blib/lib/Plack/App/Directory/PYX.pm
Criterion Covered Total %
statement 48 48 100.0
branch 10 10 100.0
condition n/a
subroutine 11 11 100.0
pod 1 1 100.0
total 70 70 100.0


line stmt bran cond sub pod time code
1             package Plack::App::Directory::PYX;
2              
3 3     3   138304 use base qw(Plack::App::Directory);
  3         21  
  3         1612  
4 3     3   285487 use strict;
  3         7  
  3         65  
5 3     3   15 use warnings;
  3         7  
  3         73  
6              
7 3     3   1103 use English;
  3         3385  
  3         23  
8 3     3   2376 use Error::Pure qw(err);
  3         14542  
  3         93  
9 3     3   1613 use PYX::SGML::Tags;
  3         86620  
  3         125  
10 3     3   24 use Plack::Util::Accessor qw(indent);
  3         7  
  3         30  
11 3     3   166 use Tags::Output::Raw;
  3         7  
  3         70  
12 3     3   1380 use Unicode::UTF8 qw(encode_utf8);
  3         1406  
  3         1097  
13              
14             our $VERSION = 0.03;
15              
16             sub serve_path {
17 8     8 1 41829 my ($self, $env, $path_to_file_or_dir) = @_;
18              
19 8 100       141 if (-d $path_to_file_or_dir) {
20             return [
21 1         15 200,
22             [
23             'Content-Type' => 'text/plain',
24             ],
25             ['DIR'],
26             ];
27             }
28              
29 7         28 my $tags = $self->_get_tags;
30 4         45 my $pyx = PYX::SGML::Tags->new(
31             'tags' => $tags,
32             );
33              
34 4         742 $pyx->parse_file($path_to_file_or_dir);
35              
36             return [
37 4         10106 200,
38             [
39             'Content-Type' => 'text/html',
40             ],
41             [encode_utf8($tags->flush)],
42             ];
43             }
44              
45             sub _get_tags {
46 7     7   15 my $self = shift;
47              
48 7         11 my $tags;
49 7 100       25 if (! defined $self->indent) {
50 2         41 $tags = Tags::Output::Raw->new;
51             } else {
52 5         37 my $class = $self->indent;
53 5         315 eval "require $class;";
54 5 100       9661 if ($EVAL_ERROR) {
55 1         8 err "Cannot load class '$class'.",
56             'Error', $EVAL_ERROR;
57             }
58 4         216 $tags = eval "$class->new";
59 4 100       511 if ($EVAL_ERROR) {
60 1         20 err "Cannot create object for '$class' class.",
61             'Error', $EVAL_ERROR;
62             }
63 3 100       25 if (! $tags->isa('Tags::Output')) {
64 1         4 err "Bad 'Tags::Output' module to create PYX output.";
65             }
66             }
67              
68 4         284 return $tags;
69             }
70              
71             1;
72              
73             __END__