blib/lib/Plack/App/Directory/PYX.pm

filter: Statementstmt 100% 50 / 50 Branchbran 100% 10 / 10 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 11 / 11 Podpod 100% 1 / 1 totaltotal 100% 72 / 72 CC 6 SCAR 8.6
CC
6
Cov
100%
_get_tags
5.0
serve_path
2.0
BEGIN
1.0
CRAP 2.4
↑ Summary
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
BranchTrueFalseTotal
if (-d $path_to_file_or_dir) 1 7 8
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
BranchTrueFalseTotal
if (not defined $self->indent) { } 2 5 7
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
BranchTrueFalseTotal
if ($Plack::App::Directory::PYX::EVAL_ERROR) 1 4 5
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
BranchTrueFalseTotal
if ($Plack::App::Directory::PYX::EVAL_ERROR) 1 3 4
60 1 err "Cannot create object for '$class' class.",
61 'Error', $EVAL_ERROR;
62 }
63 3 ▶ if (! $tags->isa('Tags::Output')) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($tags->isa("Tags::Output")) 1 2 3
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__
↑ Summary