blib/lib/Magpie/Resource/File.pm

filter: Statementstmt 62.8% 22 / 35 Branchbran 16.6% 1 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 57.1% 4 / 7 Podpod 0.0% 0 / 3 totaltotal 52.9% 27 / 51 CC 4 SCAR 12.0
CC
4
Cov
56%
_build_root
6.0
mtime
6.0
GET
2.0
CRAP 3.3
« blib/lib/Magpie/Types.pm ↑ Summary blib/lib/Magpie/Resource.pm »
1 package Magpie::Resource::File;
2 # ABSTRACT: INCOMPLETE - Basic file Resource implementation.
3 1 $Magpie::Resource::File::VERSION = '1.141660';
4 1 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 extends 'Magpie::Resource';
6 1 ▶use Magpie::Constants;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use Plack::App::File;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 1 has root => (
10 #traits => [ qw(MooseX::UndefTolerant::Attribute)],
11 is => 'rw',
12 isa => 'Str',
13 lazy_build => 1,
14 );
15  
16 sub _build_root {
17 0 ▶ my $self = shift;
Subroutine _build_root: not called CC=2 SCAR=17.9
18 0 warn "buildroot called";
19 0 my $docroot = undef;
20 0 ▶ if ( defined $self->request->env->{DOCUMENT_ROOT} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->request->env->{'DOCUMENT_ROOT'}) { } 0 0 0
21 0 $docroot = $self->request->env->{DOCUMENT_ROOT};
22 }
23 else {
24 0 $docroot = Cwd::getcwd;
25 }
26  
27 0 return Cwd::realpath($docroot);
28 }
29  
30 sub absolute_path {
31 0 ▶ my $self = shift;
Subroutine absolute_path: not called CC=1 SCAR=6.9
Pod undocumented
32 0 return Cwd::realpath($self->root . $self->request->env->{PATH_INFO});
33 }
34  
35 sub mtime {
36 0 ▶ my @stat = stat(shift->absolute_path);
Subroutine mtime: not called CC=2 SCAR=17.9
Pod undocumented
37 0 ▶ return scalar @stat ? $stat[9] : -1;
Branch: 1 branch
BranchTrueFalseTotal
scalar @stat ? : 0 0 0
38 }
39  
40 sub GET {
41 2 ▶ my $self = shift;
Subroutine GET: called CC=2 SCAR=7.2
Pod undocumented
42 2 my $ctxt = shift;
43 2 my %paf_args = ();
44 2 my $paf = Plack::App::File->new(root => $self->root);
45 2 my $r = $paf->call($self->request->env);
46  
47 2 ▶ unless ( $r->[0] == 200 ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($r->[0] == 200) 0 2 2
48 $self->set_error({
49 status_code => $r->[0],
50 additional_headers => $r->[1],
51 0 reason => join "\n", @{$r->[2]},
52 });
53 }
54 2 $self->parent_handler->resource($self);
55 2 $self->data( $r->[2] );
56  
57 2 return OK;
58 }
59  
60 1 1;
61  
62  
63  
64 =pod
65  
66 =head1 NAME
67  
68 Magpie::Resource::File - INCOMPLETE - Basic file Resource implementation.
69  
70 =head1 VERSION
71  
72 version 1.141660
73  
74 # SEALSO: Magpie, Magpie::Resource
75  
76 =head1 AUTHORS
77  
78 =over 4
79  
80 =item *
81  
82 Kip Hampton <kip.hampton@tamarou.com>
83  
84 =item *
85  
86 Chris Prather <chris.prather@tamarou.com>
87  
88 =back
89  
90 =head1 COPYRIGHT AND LICENSE
91  
92 This software is copyright (c) 2011 by Tamarou, LLC.
93  
94 This is free software; you can redistribute it and/or modify it under
95 the same terms as the Perl 5 programming language system itself.
96  
97 =cut
98  
99  
100 __END__
« blib/lib/Magpie/Types.pm ↑ Summary blib/lib/Magpie/Resource.pm »