File Coverage

blib/lib/Statocles/Page/File.pm
Criterion Covered Total %
statement 7 9 77.7
branch 2 2 100.0
condition n/a
subroutine 3 5 60.0
pod 4 4 100.0
total 16 20 80.0


line stmt bran cond sub pod time code
1             package Statocles::Page::File;
2             our $VERSION = '0.085';
3             # ABSTRACT: A page wrapping a file (handle)
4              
5 59     59   1490 use Statocles::Base 'Class';
  59         315  
  59         520  
6             with 'Statocles::Page';
7              
8             #pod =attr file_path
9             #pod
10             #pod The path to the file.
11             #pod
12             #pod =cut
13              
14             has file_path => (
15             is => 'ro',
16             isa => Path,
17             coerce => Path->coercion,
18             );
19              
20             #pod =attr fh
21             #pod
22             #pod The file handle containing the contents of the page.
23             #pod
24             #pod =cut
25              
26             has fh => (
27             is => 'ro',
28             isa => FileHandle,
29             );
30              
31             #pod =method vars
32             #pod
33             #pod Dies. This page has no templates and no template variables.
34             #pod
35             #pod =cut
36              
37             # XXX: This may have to be implemented in the future, to allow for some useful edge
38             # cases.
39 0     0 1 0 sub vars { die "Unimplemented" }
40              
41             #pod =attr dom
42             #pod
43             #pod This page has no DOM, so trying to access it throws an exception.
44             #pod
45             #pod =cut
46              
47 0     0 1 0 sub dom { die "Unimplemented" }
48              
49             #pod =method has_dom
50             #pod
51             #pod Returns false. This page has no DOM.
52             #pod
53             #pod =cut
54              
55 383     383 1 1485 sub has_dom { 0 }
56              
57             #pod =method render
58             #pod
59             #pod my $fh = $page->render;
60             #pod
61             #pod Return the filehandle to the file containing the content for this page.
62             #pod
63             #pod =cut
64              
65             sub render {
66 492     492 1 55013 my ( $self ) = @_;
67 492         7864 $self->site->log->debug( 'Render page: ' . $self->path );
68 492 100       48556 return $self->file_path ? $self->file_path : $self->fh;
69             }
70              
71             1;
72              
73             __END__
74              
75             =pod
76              
77             =encoding UTF-8
78              
79             =head1 NAME
80              
81             Statocles::Page::File - A page wrapping a file (handle)
82              
83             =head1 VERSION
84              
85             version 0.085
86              
87             =head1 SYNOPSIS
88              
89             # File path
90             my $page = Statocles::Page::File->new(
91             path => '/path/to/page.txt',
92             file_path => '/path/to/file.txt',
93             );
94              
95             # Filehandle
96             open my $fh, '<', '/path/to/file.txt';
97             my $page = Statocles::Page::File->new(
98             path => '/path/to/page.txt',
99             fh => $fh,
100             );
101              
102             =head1 DESCRIPTION
103              
104             This L<Statocles::Page> wraps a file handle in order to move files from one
105             L<store|Statocles::Store> to another.
106              
107             =head1 ATTRIBUTES
108              
109             =head2 file_path
110              
111             The path to the file.
112              
113             =head2 fh
114              
115             The file handle containing the contents of the page.
116              
117             =head2 dom
118              
119             This page has no DOM, so trying to access it throws an exception.
120              
121             =head1 METHODS
122              
123             =head2 vars
124              
125             Dies. This page has no templates and no template variables.
126              
127             =head2 has_dom
128              
129             Returns false. This page has no DOM.
130              
131             =head2 render
132              
133             my $fh = $page->render;
134              
135             Return the filehandle to the file containing the content for this page.
136              
137             =head1 AUTHOR
138              
139             Doug Bell <preaction@cpan.org>
140              
141             =head1 COPYRIGHT AND LICENSE
142              
143             This software is copyright (c) 2016 by Doug Bell.
144              
145             This is free software; you can redistribute it and/or modify it under
146             the same terms as the Perl 5 programming language system itself.
147              
148             =cut