| 1 | package Plack::App::Directory::PYX; | ||||||||||
| 2 | |||||||||||
| 3 | 3 | ▶ | use base qw(Plack::App::Directory); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 3 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 3 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | |||||||||||
| 7 | 3 | ▶ | use English; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | 3 | ▶ | use Error::Pure qw(err); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | 3 | ▶ | use PYX::SGML::Tags; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | 3 | ▶ | use Plack::Util::Accessor qw(indent); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 11 | 3 | ▶ | use Tags::Output::Raw; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 12 | 3 | ▶ | use Unicode::UTF8 qw(encode_utf8); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 13 | |||||||||||
| 14 | 3 | our $VERSION = 0.05; | |||||||||
| 15 | |||||||||||
| 16 | 8 | ▶ | sub serve_path { | ||||||||
|
Subroutine
serve_path: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||
| 17 | 8 | my ($self, $env, $path_to_file_or_dir) = @_; | |||||||||
| 18 | |||||||||||
| 19 | 8 | ▶ | if (-d $path_to_file_or_dir) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 20 | return [ | ||||||||||
| 21 | 1 | 200, | |||||||||
| 22 | [ | ||||||||||
| 23 | 'Content-Type' => 'text/plain', | ||||||||||
| 24 | ], | ||||||||||
| 25 | ['DIR'], | ||||||||||
| 26 | ]; | ||||||||||
| 27 | } | ||||||||||
| 28 | |||||||||||
| 29 | 7 | my $tags = $self->_get_tags; | |||||||||
| 30 | 4 | my $pyx = PYX::SGML::Tags->new( | |||||||||
| 31 | 'tags' => $tags, | ||||||||||
| 32 | ); | ||||||||||
| 33 | |||||||||||
| 34 | 4 | $pyx->parse_file($path_to_file_or_dir); | |||||||||
| 35 | |||||||||||
| 36 | return [ | ||||||||||
| 37 | 4 | 200, | |||||||||
| 38 | [ | ||||||||||
| 39 | 'Content-Type' => 'text/html', | ||||||||||
| 40 | ], | ||||||||||
| 41 | [encode_utf8($tags->flush)], | ||||||||||
| 42 | ]; | ||||||||||
| 43 | } | ||||||||||
| 44 | |||||||||||
| 45 | 7 | ▶ | sub _get_tags { | ||||||||
|
Subroutine
_get_tags: called CC=5 SCAR=16.1
| |||||||||||
| 46 | 7 | my $self = shift; | |||||||||
| 47 | |||||||||||
| 48 | 7 | my $tags; | |||||||||
| 49 | 7 | ▶ | if (! defined $self->indent) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 50 | 2 | $tags = Tags::Output::Raw->new; | |||||||||
| 51 | } else { | ||||||||||
| 52 | 5 | my $class = $self->indent; | |||||||||
| 53 | 5 | eval "require $class;"; | |||||||||
| 54 | 5 | ▶ | if ($EVAL_ERROR) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 55 | 1 | err "Cannot load class '$class'.", | |||||||||
| 56 | 'Error', $EVAL_ERROR; | ||||||||||
| 57 | } | ||||||||||
| 58 | 4 | $tags = eval "$class->new"; | |||||||||
| 59 | 4 | ▶ | if ($EVAL_ERROR) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 60 | 1 | err "Cannot create object for '$class' class.", | |||||||||
| 61 | 'Error', $EVAL_ERROR; | ||||||||||
| 62 | } | ||||||||||
| 63 | 3 | ▶ | if (! $tags->isa('Tags::Output')) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 64 | 1 | err "Bad 'Tags::Output' module to create PYX output."; | |||||||||
| 65 | } | ||||||||||
| 66 | } | ||||||||||
| 67 | |||||||||||
| 68 | 4 | return $tags; | |||||||||
| 69 | } | ||||||||||
| 70 | |||||||||||
| 71 | 3 | 1; | |||||||||
| 72 | |||||||||||
| 73 | __END__ | ||||||||||