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   116231 use base qw(Plack::App::Directory);
  3         16  
  3         1352  
4 3     3   250816 use strict;
  3         7  
  3         88  
5 3     3   15 use warnings;
  3         6  
  3         72  
6              
7 3     3   1070 use English;
  3         3462  
  3         16  
8 3     3   1960 use Error::Pure qw(err);
  3         12953  
  3         81  
9 3     3   1472 use PYX::SGML::Tags;
  3         78380  
  3         102  
10 3     3   21 use Plack::Util::Accessor qw(indent);
  3         6  
  3         29  
11 3     3   151 use Tags::Output::Raw;
  3         6  
  3         59  
12 3     3   1227 use Unicode::UTF8 qw(encode_utf8);
  3         1296  
  3         830  
13              
14             our $VERSION = 0.05;
15              
16             sub serve_path {
17 8     8 1 34937 my ($self, $env, $path_to_file_or_dir) = @_;
18              
19 8 100       128 if (-d $path_to_file_or_dir) {
20             return [
21 1         11 200,
22             [
23             'Content-Type' => 'text/plain',
24             ],
25             ['DIR'],
26             ];
27             }
28              
29 7         27 my $tags = $self->_get_tags;
30 4         31 my $pyx = PYX::SGML::Tags->new(
31             'tags' => $tags,
32             );
33              
34 4         315 $pyx->parse_file($path_to_file_or_dir);
35              
36             return [
37 4         8359 200,
38             [
39             'Content-Type' => 'text/html',
40             ],
41             [encode_utf8($tags->flush)],
42             ];
43             }
44              
45             sub _get_tags {
46 7     7   13 my $self = shift;
47              
48 7         8 my $tags;
49 7 100       17 if (! defined $self->indent) {
50 2         38 $tags = Tags::Output::Raw->new;
51             } else {
52 5         32 my $class = $self->indent;
53 5         283 eval "require $class;";
54 5 100       8015 if ($EVAL_ERROR) {
55 1         6 err "Cannot load class '$class'.",
56             'Error', $EVAL_ERROR;
57             }
58 4         170 $tags = eval "$class->new";
59 4 100       427 if ($EVAL_ERROR) {
60 1         4 err "Cannot create object for '$class' class.",
61             'Error', $EVAL_ERROR;
62             }
63 3 100       19 if (! $tags->isa('Tags::Output')) {
64 1         4 err "Bad 'Tags::Output' module to create PYX output.";
65             }
66             }
67              
68 4         215 return $tags;
69             }
70              
71             1;
72              
73             __END__