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   140471 use base qw(Plack::App::Directory);
  3         16  
  3         1675  
4 3     3   294092 use strict;
  3         14  
  3         181  
5 3     3   19 use warnings;
  3         6  
  3         75  
6              
7 3     3   1132 use English;
  3         3429  
  3         24  
8 3     3   2439 use Error::Pure qw(err);
  3         14785  
  3         95  
9 3     3   1654 use PYX::SGML::Tags;
  3         88430  
  3         113  
10 3     3   27 use Plack::Util::Accessor qw(indent);
  3         8  
  3         38  
11 3     3   154 use Tags::Output::Raw;
  3         10  
  3         63  
12 3     3   1448 use Unicode::UTF8 qw(encode_utf8);
  3         1438  
  3         1033  
13              
14             our $VERSION = 0.04;
15              
16             sub serve_path {
17 8     8 1 43447 my ($self, $env, $path_to_file_or_dir) = @_;
18              
19 8 100       156 if (-d $path_to_file_or_dir) {
20             return [
21 1         12 200,
22             [
23             'Content-Type' => 'text/plain',
24             ],
25             ['DIR'],
26             ];
27             }
28              
29 7         32 my $tags = $self->_get_tags;
30 4         35 my $pyx = PYX::SGML::Tags->new(
31             'tags' => $tags,
32             );
33              
34 4         764 $pyx->parse_file($path_to_file_or_dir);
35              
36             return [
37 4         10257 200,
38             [
39             'Content-Type' => 'text/html',
40             ],
41             [encode_utf8($tags->flush)],
42             ];
43             }
44              
45             sub _get_tags {
46 7     7   11 my $self = shift;
47              
48 7         24 my $tags;
49 7 100       24 if (! defined $self->indent) {
50 2         26 $tags = Tags::Output::Raw->new;
51             } else {
52 5         36 my $class = $self->indent;
53 5         314 eval "require $class;";
54 5 100       9797 if ($EVAL_ERROR) {
55 1         7 err "Cannot load class '$class'.",
56             'Error', $EVAL_ERROR;
57             }
58 4         196 $tags = eval "$class->new";
59 4 100       493 if ($EVAL_ERROR) {
60 1         6 err "Cannot create object for '$class' class.",
61             'Error', $EVAL_ERROR;
62             }
63 3 100       24 if (! $tags->isa('Tags::Output')) {
64 1         5 err "Bad 'Tags::Output' module to create PYX output.";
65             }
66             }
67              
68 4         261 return $tags;
69             }
70              
71             1;
72              
73             __END__