SSI/Finfo.pm

filter: Statementstmt 47.6% 169 / 355 Branchbran 7.5% 8 / 106 Conditioncond 5.2% 1 / 19 MC/DCmcdc 0.0% 0 / 12 Subroutinesub 59.3% 54 / 91 Podpod 95.1% 39 / 41 totaltotal 43.4% 271 / 624 CC 61 SCAR 22.5
CC
61
Cov
37%
filetype
45.2
stat
20.0
_datetime
20.0
CRAP 9.5
« SSI/Common.pm ↑ Summary
1 ## <https://perl.apache.org/docs/2.0/api/APR/Finfo.html>
2 ##----------------------------------------------------------------------------
3 ## Apache2 Server Side Include Parser - ~/lib/Apache2/SSI/Finfo.pm
4 ## Version v0.1.3
5 ## Copyright(c) 2022 DEGUEST Pte. Ltd.
6 ## Author: Jacques Deguest <jack@deguest.jp>
7 ## Created 2020/12/18
8 ## Modified 2024/09/04
9 ## All rights reserved
10 ##
11 ## This program is free software; you can redistribute it and/or modify it
12 ## under the same terms as Perl itself.
13 ##----------------------------------------------------------------------------
14 package Apache2::SSI::Finfo;
15 BEGIN
16 9 ▶{
Subroutine BEGIN: called CC=2 SCAR=6.9
17 9 ▶ use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 9 ▶ use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 9 ▶ use warnings::register;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 9 ▶ use parent qw( Module::Generic );
Subroutine BEGIN: called CC=1 SCAR=0.0
21 9 ▶ use vars qw( $VERSION $AUTOLOAD %EXPORT_TAGS @EXPORT_OK $ERROR );
Subroutine BEGIN: called CC=1 SCAR=0.0
22 9 ▶ use Apache2::SSI::File::Type;
Subroutine BEGIN: called CC=1 SCAR=0.0
23 9 ▶ use Exporter qw( import );
Subroutine BEGIN: called CC=1 SCAR=0.0
24 9 ▶ use DateTime;
Subroutine BEGIN: called CC=1 SCAR=0.0
25 9 ▶ use DateTime::Format::Strptime;
Subroutine BEGIN: called CC=1 SCAR=0.0
26 9 ▶ use File::Basename ();
Subroutine BEGIN: called CC=1 SCAR=0.0
27 9 our( $AUTOLOAD, $ERROR );
28 9 ▶ use overload (
Subroutine BEGIN: called CC=1 SCAR=0.2
29 0 ▶ q{""} => sub { $_[0]->{filepath} },
Subroutine __ANON__: not called CC=1 SCAR=6.9
30 bool => sub () { 1 },
31 9 fallback => 1,
32 9 );
33 9 ▶ if( exists( $ENV{MOD_PERL} ) )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $ENV{"MOD_PERL"}) 0 9 9
34 {
35 0 require APR::Pool;
36 0 require APR::Finfo;
37 0 require APR::Const;
38 0 APR::Const->import( -compile => qw( :filetype FINFO_NORM ) );
39 }
40 9 ▶ use constant FINFO_DEV => 0;
Subroutine BEGIN: called CC=1 SCAR=0.0
41 9 ▶ use constant FINFO_INODE => 1;
Subroutine BEGIN: called CC=1 SCAR=0.0
42 9 ▶ use constant FINFO_MODE => 2;
Subroutine BEGIN: called CC=1 SCAR=0.0
43 9 ▶ use constant FINFO_NLINK => 3;
Subroutine BEGIN: called CC=1 SCAR=0.0
44 9 ▶ use constant FINFO_UID => 4;
Subroutine BEGIN: called CC=1 SCAR=0.0
45 9 ▶ use constant FINFO_GID => 5;
Subroutine BEGIN: called CC=1 SCAR=0.0
46 9 ▶ use constant FINFO_RDEV => 6;
Subroutine BEGIN: called CC=1 SCAR=0.0
47 9 ▶ use constant FINFO_SIZE => 7;
Subroutine BEGIN: called CC=1 SCAR=0.0
48 9 ▶ use constant FINFO_ATIME => 8;
Subroutine BEGIN: called CC=1 SCAR=0.0
49 9 ▶ use constant FINFO_MTIME => 9;
Subroutine BEGIN: called CC=1 SCAR=0.0
50 9 ▶ use constant FINFO_CTIME => 10;
Subroutine BEGIN: called CC=1 SCAR=0.0
51 9 ▶ use constant FINFO_BLOCK_SIZE => 11;
Subroutine BEGIN: called CC=1 SCAR=0.0
52 9 ▶ use constant FINFO_BLOCKS => 12;
Subroutine BEGIN: called CC=1 SCAR=0.0
53 # Sames constant value as in APR::Const
54 # the file type is undetermined.
55 9 ▶ use constant FILETYPE_NOFILE => 0;
Subroutine BEGIN: called CC=1 SCAR=0.0
56 # a file is a regular file.
57 9 ▶ use constant FILETYPE_REG => 1;
Subroutine BEGIN: called CC=1 SCAR=0.0
58 # a file is a directory
59 9 ▶ use constant FILETYPE_DIR => 2;
Subroutine BEGIN: called CC=1 SCAR=0.0
60 # a file is a character device
61 9 ▶ use constant FILETYPE_CHR => 3;
Subroutine BEGIN: called CC=1 SCAR=0.0
62 # a file is a block device
63 9 ▶ use constant FILETYPE_BLK => 4;
Subroutine BEGIN: called CC=1 SCAR=0.0
64 # a file is a FIFO or a pipe.
65 9 ▶ use constant FILETYPE_PIPE => 5;
Subroutine BEGIN: called CC=1 SCAR=0.0
66 # a file is a symbolic link
67 9 ▶ use constant FILETYPE_LNK => 6;
Subroutine BEGIN: called CC=1 SCAR=0.0
68 # a file is a [unix domain] socket.
69 9 ▶ use constant FILETYPE_SOCK => 7;
Subroutine BEGIN: called CC=1 SCAR=0.0
70 # a file is of some other unknown type or the type cannot be determined.
71 9 ▶ use constant FILETYPE_UNKFILE => 127;
Subroutine BEGIN: called CC=1 SCAR=0.0
72 9 our %EXPORT_TAGS = ( all => [qw( FILETYPE_NOFILE FILETYPE_REG FILETYPE_DIR FILETYPE_CHR FILETYPE_BLK FILETYPE_PIPE FILETYPE_LNK FILETYPE_SOCK FILETYPE_UNKFILE )] );
73 9 our @EXPORT_OK = qw( FILETYPE_NOFILE FILETYPE_REG FILETYPE_DIR FILETYPE_CHR FILETYPE_BLK FILETYPE_PIPE FILETYPE_LNK FILETYPE_SOCK FILETYPE_UNKFILE );
74 9 our $VERSION = 'v0.1.3';
75 };
76  
77 9 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
78 9 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
79  
80 sub init
81 75 ▶{
Subroutine init: called CC=6 SCAR=25.9
Pod documented
82 75 my $self = shift( @_ );
83 75 ▶ my $file = shift( @_ ) || return( $self->error( "No file provided to instantiate a ", ref( $self ), " object." ) );
Condition50%1/2
shift @_ || (return $self->error('No file provided to instantiate a ', ref $self, ' object.'))
l!l
750
MC/DC0%0/1
shift @_ || (return $self->error('No file provided to instantiate a ', ref $self, ' object.'))
shift @_
Truth table50%1/2
A
A= shift @_
Aresult
11
00
84 # return( $self->error( "File or directory \"$file\" does not exist." ) ) if( !-e( $file ) );
85 75 $self->{apache_request} = '';
86 75 $self->{apr_finfo} = '';
87 75 $self->{_init_strict_use_sub} = 1;
88 75 $self->SUPER::init( @_ );
89 75 $self->{filepath} = $file;
90 75 $self->{_data} = [];
91 75 my $r = $self->{apache_request};
92 75 ▶ if( $r )
Branch: 1 branch
BranchTrueFalseTotal
if ($r) { } 0 75 75
93 {
94 # <https://perl.apache.org/docs/2.0/api/Apache2/RequestRec.html#toc_C_filename_>
95 0 local $@;
96 # try-catch
97 eval
98 0 {
99 0 my $finfo;
100 0 ▶ if( $r->filename eq $file )
Branch: 1 branch
BranchTrueFalseTotal
if ($r->filename eq $file) { } 0 0 0
101 {
102 0 $finfo = $r->finfo;
103 }
104 else
105 {
106 0 $finfo = APR::Finfo::stat( $file, &APR::Const::FINFO_NORM, $r->pool );
107 0 $r->finfo( $finfo );
108 }
109 0 $self->{apr_finfo} = $finfo;
110 };
111 0 ▶ if( $@ )
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
112 {
113 # This makes it possible to query this api even if provided with a non-existing file
114 0 ▶ if( $@ =~ /No[[:blank:]\h]+such[[:blank:]\h]+file[[:blank:]\h]+or[[:blank:]\h]+directory/i )
Branch: 1 branch
BranchTrueFalseTotal
if ($@ =~ /No[[:blank:]\h]+such[[:blank:]\h]+file[[:blank:]\h]+or[[:blank:]\h]+directory/i) { } 0 0 0
115 {
116 0 $self->{_data} = [];
117 }
118 else
119 {
120 0 return( $self->error( "Unable to set the APR::Finfo object: $@" ) );
121 }
122 }
123 }
124 else
125 {
126 75 $self->{_data} = [CORE::stat( $file )];
127 }
128 75 return( $self );
129 }
130  
131 2 ▶sub apache_request { return( shift->_set_get_object_without_init( 'apache_request', 'Apache2::RequestRec', @_ ) ); }
Subroutine apache_request: called CC=1 SCAR=0.0
Pod documented
132  
133 4 ▶sub apr_finfo { return( shift->_set_get_object( 'apr_finfo', 'APR::Finfo', @_ ) ); }
Subroutine apr_finfo: called CC=1 SCAR=0.0
Pod documented
134  
135 sub atime
136 0 ▶{
Subroutine atime: not called CC=3 SCAR=24.8
Pod documented
137 0 my $self = shift( @_ );
138 0 my $f = $self->apr_finfo;
139 0 my $t;
140 0 ▶ if( $f )
Branch: 1 branch
BranchTrueFalseTotal
if ($f) { } 0 0 0
141 {
142 0 $t = $f->atime;
143 }
144 else
145 {
146 0 my $data = $self->{_data};
147 0 ▶ return( '' ) if( !scalar( @$data ) );
Branch: 1 branch
BranchTrueFalseTotal
unless scalar @$data 0 0 0
148 0 $t = $data->[ FINFO_ATIME ];
149 }
150 0 return( $self->_datetime( $t ) );
151 }
152  
153 0 ▶sub blksize { return( shift->block_size( @_ ) ); }
Subroutine blksize: not called CC=1 SCAR=6.9
Pod documented
154  
155 sub block_size
156 0 ▶{
Subroutine block_size: not called CC=3 SCAR=24.8
Pod undocumented
157 0 my $self = shift( @_ );
158 0 my $f = $self->apr_finfo;
159 0 ▶ if( $f )
Branch: 1 branch
BranchTrueFalseTotal
if ($f) { } 0 0 0
160 {
161 0 return( ( CORE::stat( $self->{filepath} ) )[ FINFO_BLOCK_SIZE ] );
162 }
163 else
164 {
165 0 my $data = $self->{_data};
166 0 ▶ return( '' ) if( !scalar( @$data ) );
Branch: 1 branch
BranchTrueFalseTotal
unless scalar @$data 0 0 0
167 0 return( $data->[ FINFO_BLOCK_SIZE ] );
168 }
169 }
170  
171 sub blocks
172 0 ▶{
Subroutine blocks: not called CC=3 SCAR=24.8
Pod documented
173 0 my $self = shift( @_ );
174 0 my $f = $self->apr_finfo;
175 0 ▶ if( $f )
Branch: 1 branch
BranchTrueFalseTotal
if ($f) { } 0 0 0
176 {
177 0 return( ( CORE::stat( $self->{filepath} ) )[ FINFO_BLOCKS ] );
178 }
179 else
180 {
181 0 my $data = $self->{_data};
182 0 ▶ return( '' ) if( !scalar( @$data ) );
Branch: 1 branch
BranchTrueFalseTotal
unless scalar @$data 0 0 0
183 0 return( $data->[ FINFO_BLOCKS ] );
184 }
185 }
186  
187 0 ▶sub can_read { return( -r( shift->filepath ) ); }
Subroutine can_read: not called CC=1 SCAR=6.9
Pod documented
188  
189 0 ▶sub can_write { return( -w( shift->filepath ) ); }
Subroutine can_write: not called CC=1 SCAR=6.9
Pod documented
190  
191 1 ▶sub can_exec { return( -x( shift->filepath ) ); }
Subroutine can_exec: called CC=1 SCAR=0.0
Pod documented
192  
193 0 ▶sub can_execute { return( -x( shift->filepath ) ); }
Subroutine can_execute: not called CC=1 SCAR=6.9
Pod documented
194  
195 0 ▶sub csize { return( shift->size ); }
Subroutine csize: not called CC=1 SCAR=6.9
Pod documented
196  
197 sub ctime
198 0 ▶{
Subroutine ctime: not called CC=3 SCAR=24.8
Pod documented
199 0 my $self = shift( @_ );
200 0 my $f = $self->apr_finfo;
201 0 my $t;
202 0 ▶ if( $f )
Branch: 1 branch
BranchTrueFalseTotal
if ($f) { } 0 0 0
203 {
204 0 $t = $f->ctime;
205 }
206 else
207 {
208 0 my $data = $self->{_data};
209 0 ▶ return( '' ) if( !scalar( @$data ) );
Branch: 1 branch
BranchTrueFalseTotal
unless scalar @$data 0 0 0
210 0 $t = $data->[ FINFO_CTIME ];
211 }
212 0 return( $self->_datetime( $t ) );
213 }
214  
215 0 ▶sub dev { return( shift->device( @_ ) ); }
Subroutine dev: not called CC=1 SCAR=6.9
Pod documented
216  
217 sub device
218 0 ▶{
Subroutine device: not called CC=3 SCAR=24.8
Pod documented
219 0 my $self = shift( @_ );
220 0 my $f = $self->apr_finfo;
221 0 ▶ if( $f )
Branch: 1 branch
BranchTrueFalseTotal
if ($f) { } 0 0 0
222 {
223 0 return( $f->device );
224 }
225 else
226 {
227 0 my $data = $self->{_data};
228 0 ▶ return( '' ) if( !scalar( @$data ) );
Branch: 1 branch
BranchTrueFalseTotal
unless scalar @$data 0 0 0
229 0 return( $data->[ FINFO_DEV ] );
230 }
231 }
232  
233 2 ▶sub exists { return( shift->filetype == FILETYPE_NOFILE ? 0 : 1 ); }
Subroutine exists: called CC=2 SCAR=7.6
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
(shift())->filetype == 0 ? : 0 2 2
234  
235 # Read-only
236 2 ▶sub filepath { return( shift->_set_get_scalar( 'filepath' ) ); }
Subroutine filepath: called CC=1 SCAR=0.0
Pod documented
237  
238 sub filetype
239 2 ▶{
Subroutine filetype: called CC=10 SCAR=38.1
Pod documented
240 2 my $self = shift( @_ );
241 2 my $f = $self->apr_finfo;
242 2 ▶ if( $f )
Branch: 1 branch
BranchTrueFalseTotal
if ($f) { } 0 2 2
243 {
244 0 return( $f->filetype );
245 }
246 else
247 {
248 2 my $file = $self->{filepath};
249 2 CORE::stat( $file );
250 2 ▶ if( !-e( _ ) )
Branch: 8 branches
BranchTrueFalseTotal
if (not -e _) { } 0 2 2
elsif (-f _) { } 2 0 2
elsif (-d _) { } 0 0 0
elsif (-l _) { } 0 0 0
elsif (-p _) { } 0 0 0
elsif (-S _) { } 0 0 0
elsif (-b _) { } 0 0 0
elsif (-c _) { } 0 0 0
251 {
252 0 return( FILETYPE_NOFILE );
253 }
254 elsif( -f( _ ) )
255 {
256 2 return( FILETYPE_REG );
257 }
258 elsif( -d( _ ) )
259 {
260 0 return( FILETYPE_DIR );
261 }
262 elsif( -l( _ ) )
263 {
264 0 return( FILETYPE_LNK );
265 }
266 elsif( -p( _ ) )
267 {
268 0 return( FILETYPE_PIPE );
269 }
270 elsif( -S( _ ) )
271 {
272 0 return( FILETYPE_SOCK );
273 }
274 elsif( -b( _ ) )
275 {
276 0 return( FILETYPE_BLK );
277 }
278 elsif( -c( _ ) )
279 {
280 0 return( FILETYPE_CHR );
281 }
282 else
283 {
284 0 return( FILETYPE_UNKFILE );
285 }
286 }
287 }
288  
289 sub fname
290 2 ▶{
Subroutine fname: called CC=2 SCAR=7.4
Pod documented
291 2 my $self = shift( @_ );
292 2 my $r = $self->apache_request;
293 2 ▶ if( $r )
Branch: 1 branch
BranchTrueFalseTotal
if ($r) { } 0 2 2
294 {
295 0 return( $r->fname );
296 }
297 else
298 {
299 2 return( $self->{filepath} );
300 }
301 }
302  
303 0 ▶sub gid { return( shift->group ); }
Subroutine gid: not called CC=1 SCAR=6.9
Pod documented
304  
305 sub group
306 0 ▶{
Subroutine group: not called CC=3 SCAR=24.8
Pod documented
307 0 my $self = shift( @_ );
308 0 my $f = $self->apr_finfo;
309 0 ▶ if( $f )
Branch: 1 branch
BranchTrueFalseTotal
if ($f) { } 0 0 0
310 {
311 0 return( $f->fname );
312 }
313 else
314 {
315 0 my $data = $self->{_data};
316 0 ▶ return( '' ) if( !scalar( @$data ) );
Branch: 1 branch
BranchTrueFalseTotal
unless scalar @$data 0 0 0
317 0 return( $data->[ FINFO_GID ] );
318 }
319 }
320  
321 0 ▶sub ino { return( shift->inode( @_ ) ); }
Subroutine ino: not called CC=1 SCAR=6.9
Pod undocumented
322  
323 sub inode
324 0 ▶{
Subroutine inode: not called CC=3 SCAR=24.8
Pod documented
325 0 my $self = shift( @_ );
326 0 my $f = $self->apr_finfo;
327 0 ▶ if( $f )
Branch: 1 branch
BranchTrueFalseTotal
if ($f) { } 0 0 0
328 {
329 0 return( $f->inode );
330 }
331 else
332 {
333 0 my $data = $self->{_data};
334 0 ▶ return( '' ) if( !scalar( @$data ) );
Branch: 1 branch
BranchTrueFalseTotal
unless scalar @$data 0 0 0
335 0 return( $data->[ FINFO_INODE ] );
336 }
337 }
338  
339 0 ▶sub is_block { return( shift->filetype == FILETYPE_BLK ); }
Subroutine is_block: not called CC=1 SCAR=6.9
Pod documented
340  
341 0 ▶sub is_char { return( shift->filetype == FILETYPE_CHR ); }
Subroutine is_char: not called CC=1 SCAR=6.9
Pod documented
342  
343 0 ▶sub is_dir { return( shift->filetype == FILETYPE_DIR ); }
Subroutine is_dir: not called CC=1 SCAR=6.9
Pod documented
344  
345 0 ▶sub is_file { return( shift->filetype == FILETYPE_REG ); }
Subroutine is_file: not called CC=1 SCAR=6.9
Pod documented
346  
347 0 ▶sub is_link { return( shift->filetype == FILETYPE_LNK ); }
Subroutine is_link: not called CC=1 SCAR=6.9
Pod documented
348  
349 0 ▶sub is_pipe { return( shift->filetype == FILETYPE_PIPE ); }
Subroutine is_pipe: not called CC=1 SCAR=6.9
Pod documented
350  
351 0 ▶sub is_socket { return( shift->filetype == FILETYPE_SOCK ); }
Subroutine is_socket: not called CC=1 SCAR=6.9
Pod documented
352  
353 sub mime_type
354 1 ▶{
Subroutine mime_type: called CC=1 SCAR=0.0
Pod documented
355 1 my $self = shift( @_ );
356 1 my $file = $self->filepath;
357 1 my $m = Apache2::SSI::File::Type->new;
358 1 return( $m->file( $file ) );
359 }
360  
361 sub mode
362 0 ▶{
Subroutine mode: not called CC=3 SCAR=24.8
Pod documented
363 0 my $self = shift( @_ );
364 0 my $f = $self->apr_finfo;
365 0 ▶ if( $f )
Branch: 1 branch
BranchTrueFalseTotal
if ($f) { } 0 0 0
366 {
367 # Something like 1860
368 0 my $hex = $f->protection;
369 0 return( oct( sprintf( '%x', $hex ) ) );
370 }
371 else
372 {
373 0 my $data = $self->{_data};
374 0 ▶ return( '' ) if( !scalar( @$data ) );
Branch: 1 branch
BranchTrueFalseTotal
unless scalar @$data 0 0 0
375 0 return( $data->[ FINFO_MODE ] & 07777 );
376 }
377 }
378  
379 sub mtime
380 0 ▶{
Subroutine mtime: not called CC=3 SCAR=24.8
Pod documented
381 0 my $self = shift( @_ );
382 0 my $f = $self->apr_finfo;
383 0 my $t;
384 0 ▶ if( $f )
Branch: 1 branch
BranchTrueFalseTotal
if ($f) { } 0 0 0
385 {
386 0 $t = $f->mtime;
387 }
388 else
389 {
390 0 my $data = $self->{_data};
391 0 ▶ return( '' ) if( !scalar( @$data ) );
Branch: 1 branch
BranchTrueFalseTotal
unless scalar @$data 0 0 0
392 0 $t = $data->[ FINFO_MTIME ];
393 }
394 0 return( $self->_datetime( $t ) );
395 }
396  
397 sub name
398 2 ▶{
Subroutine name: called CC=3 SCAR=14.2
Pod documented
399 2 my $self = shift( @_ );
400 2 my $f = $self->apr_finfo;
401 2 ▶ if( $f )
Branch: 1 branch
BranchTrueFalseTotal
if ($f) { } 0 2 2
402 {
403 0 ▶ return( $f->name || File::Basename::basename( $f->fname ) );
Condition0%0/3
$f->name || File::Basename::basename($f->fname)
l!l&&r!l&&!r
000
MC/DC0%0/2
$f->name || File::Basename::basename($f->fname)
$f->name File::Basename::basename($f->fname)
Truth table0%0/3
A || B
A= $f->nameB= File::Basename::basename($f->fname)
ABresult
1X1
011
000
404 }
405 else
406 {
407 2 return( File::Basename::basename( $self->fname ) );
408 }
409 }
410  
411 sub nlink
412 0 ▶{
Subroutine nlink: not called CC=3 SCAR=24.8
Pod documented
413 0 my $self = shift( @_ );
414 0 my $f = $self->apr_finfo;
415 0 ▶ if( $f )
Branch: 1 branch
BranchTrueFalseTotal
if ($f) { } 0 0 0
416 {
417 0 return( $f->nlink );
418 }
419 else
420 {
421 0 my $data = $self->{_data};
422 0 ▶ return( '' ) if( !scalar( @$data ) );
Branch: 1 branch
BranchTrueFalseTotal
unless scalar @$data 0 0 0
423 0 return( $data->[ FINFO_NLINK ] );
424 }
425 }
426  
427 sub protection
428 0 ▶{
Subroutine protection: not called CC=3 SCAR=24.8
Pod documented
429 0 my $self = shift( @_ );
430 0 my $f = $self->apr_finfo;
431 0 ▶ if( $f )
Branch: 1 branch
BranchTrueFalseTotal
if ($f) { } 0 0 0
432 {
433 # Will return something like 1860 (i.e. 744 = hex(1860))
434 0 return( $f->protection );
435 }
436 else
437 {
438 0 my @stat = CORE::stat( $self->filepath );
439 0 ▶ return( '' ) if( !scalar( @stat ) );
Branch: 1 branch
BranchTrueFalseTotal
unless scalar @stat 0 0 0
440 0 return( hex( sprintf( '%04o', $stat[2] & 07777 ) ) );
441 }
442 }
443  
444 sub rdev
445 0 ▶{
Subroutine rdev: not called CC=3 SCAR=24.8
Pod documented
446 0 my $self = shift( @_ );
447 0 my $f = $self->apr_finfo;
448 0 ▶ if( $f )
Branch: 1 branch
BranchTrueFalseTotal
if ($f) { } 0 0 0
449 {
450 0 return( ( CORE::stat( $self->{filepath} ) )[ FINFO_RDEV ] );
451 }
452 else
453 {
454 0 my $data = $self->{_data};
455 0 ▶ return( '' ) if( !scalar( @$data ) );
Branch: 1 branch
BranchTrueFalseTotal
unless scalar @$data 0 0 0
456 0 return( $data->[ FINFO_RDEV ] );
457 }
458 }
459  
460 sub size
461 0 ▶{
Subroutine size: not called CC=3 SCAR=24.8
Pod documented
462 0 my $self = shift( @_ );
463 0 my $f = $self->apr_finfo;
464 0 ▶ if( $f )
Branch: 1 branch
BranchTrueFalseTotal
if ($f) { } 0 0 0
465 {
466 0 return( $f->size );
467 }
468 else
469 {
470 0 my $data = $self->{_data};
471 0 ▶ return( '' ) if( !scalar( @$data ) );
Branch: 1 branch
BranchTrueFalseTotal
unless scalar @$data 0 0 0
472 0 return( $data->[ FINFO_SIZE ] );
473 }
474 }
475  
476 sub stat
477 0 ▶{
Subroutine stat: not called CC=4 SCAR=30.0
Pod documented
478 0 my $self = shift( @_ );
479 0 my $r = $self->apache_request;
480 0 my $file = shift( @_ );
481 0 ▶ my $p = scalar( @_ ) ? { @_ } : {};
Branch: 1 branch
BranchTrueFalseTotal
scalar @_ ? : 0 0 0
482 0 ▶ $p->{apache_request} = $r if( $r && !$p->{apache_request} );
Branch: 1 branch
BranchTrueFalseTotal
if $r and not $p->{"apache_request"} 0 0 0
Condition0%0/3
$r and not $p->{"apache_request"}
!ll&&!rl&&r
000
MC/DC0%0/2
$r and not $p->{"apache_request"}
$r not $p->{"apache_request"}
Truth table0%0/3
A and not(B)
A= $rB= not $p->{"apache_request"}
ABresult
0X0
100
111
483 0 return( $self->new( $file, $p ) );
484 }
485  
486 0 ▶sub uid { return( shift->user ); }
Subroutine uid: not called CC=1 SCAR=6.9
Pod documented
487  
488 sub user
489 0 ▶{
Subroutine user: not called CC=3 SCAR=24.8
Pod documented
490 0 my $self = shift( @_ );
491 0 my $f = $self->apr_finfo;
492 0 ▶ if( $f )
Branch: 1 branch
BranchTrueFalseTotal
if ($f) { } 0 0 0
493 {
494 0 return( $f->user );
495 }
496 else
497 {
498 0 my $data = $self->{_data};
499 0 ▶ return( '' ) if( !scalar( @$data ) );
Branch: 1 branch
BranchTrueFalseTotal
unless scalar @$data 0 0 0
500 0 return( $data->[ FINFO_UID ] );
501 }
502 }
503  
504 sub _datetime
505 0 ▶{
Subroutine _datetime: not called CC=4 SCAR=30.0
506 0 my $self = shift( @_ );
507 0 my $t = shift( @_ );
508 0 ▶ return( $self->error( "No epoch time was provided." ) ) if( !length( $t ) );
Branch: 1 branch
BranchTrueFalseTotal
unless length $t 0 0 0
509 0 ▶ return( $self->error( "Invalid epoch time provided \"$t\"." ) ) if( $t !~ /^\d+$/ );
Branch: 1 branch
BranchTrueFalseTotal
unless $t =~ /^\d+$/ 0 0 0
510 0 local $@;
511 # try-catch
512 my $rv = eval
513 0 {
514 0 my $dt = DateTime->from_epoch( epoch => $t, time_zone => 'local' );
515 0 my $fmt = DateTime::Format::Strptime->new(
516 pattern => '%s',
517 time_zone => 'local',
518 );
519 0 $dt->set_formatter( $fmt );
520 0 return( Apache2::SSI::Datetime->new( $dt ) );
521 };
522 0 ▶ if( $@ )
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
523 {
524 0 return( $self->error( "Unable to get the datetime object for \"$t\": $@" ) );
525 }
526 0 return( $rv );
527 }
528  
529 # NOTE: Apache2::SSI::Datetime class
530 package Apache2::SSI::Datetime;
531 BEGIN
532 9 ▶{
Subroutine BEGIN: called CC=1 SCAR=0.0
533 9 ▶ use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
534 9 ▶ use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
535 9 ▶ use vars qw( $ERROR );
Subroutine BEGIN: called CC=1 SCAR=0.0
536 9 ▶ use overload (
Subroutine BEGIN: called CC=1 SCAR=0.2
537 0 ▶ q{""} => sub { $_[0]->{dt}->stringify },
Subroutine __ANON__: not called CC=1 SCAR=6.9
538 bool => sub () { 1 },
539 9 fallback => 1,
540 9 );
541 9 our( $ERROR );
542 };
543  
544 9 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
545 9 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
546  
547 sub new
548 0 ▶{
Subroutine new: not called CC=3 SCAR=24.8
549 0 my $this = shift( @_ );
550 0 ▶ my $dt = shift( @_ ) || return;
Condition0%0/2
shift @_ || (return)
l!l
00
MC/DC0%0/1
shift @_ || (return)
shift @_
Truth table0%0/2
A
A= shift @_
Aresult
11
00
551 0 my $self = { dt => $dt };
552 0 ▶ return( bless( { dt => $dt } => ( ref( $this ) || $this ) ) );
Condition0%0/3
ref $this || $this
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $this || $this
ref $this $this
Truth table0%0/3
A || B
A= ref $thisB= $this
ABresult
1X1
011
000
553 }
554  
555 sub error
556 0 ▶{
Subroutine error: not called CC=3 SCAR=24.8
557 0 my $self = shift( @_ );
558 0 ▶ if( @_ )
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
559 {
560  
561 0 $self->{error} = $ERROR = join( '', @_ );
562 0 return;
563 }
564 0 ▶ return( $self->{error} || $ERROR );
Condition0%0/3
$self->{'error'} || $Apache2::SSI::Datetime::ERROR
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->{'error'} || $Apache2::SSI::Datetime::ERROR
$self->{'error'} $Apache2::SSI::Datetime::ERROR
Truth table0%0/3
A || B
A= $self->{'error'}B= $Apache2::SSI::Datetime::ERROR
ABresult
1X1
011
000
565 }
566  
567 AUTOLOAD
568 0 ▶{
Subroutine AUTOLOAD: not called CC=4 SCAR=25.8
569 0 my( $method ) = our $AUTOLOAD =~ /([^:]+)$/;
570 9 ▶ no overloading;
Subroutine BEGIN: called CC=1 SCAR=0.0
571 0 my $self = shift( @_ );
572 0 ▶ my $class = ref( $self ) || $self;
Condition0%0/3
ref $self || $self
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $self || $self
ref $self $self
Truth table0%0/3
A || B
A= ref $selfB= $self
ABresult
1X1
011
000
573 0 ▶ die( "DateTime object is gone !\n" ) if( !ref( $self->{dt} ) );
Branch: 1 branch
BranchTrueFalseTotal
unless ref $self->{"dt"} 0 0 0
574 0 my $dt = $self->{dt};
575 0 ▶ if( $dt->can( $method ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($dt->can($method)) { } 0 0 0
576 {
577 0 return( $dt->$method( @_ ) );
578 }
579 else
580 {
581 0 return( $self->error( "No method \"$method\" available in DateTime" ) );
582 }
583 };
584  
585 9 1;
586 # NOTE: POD
587 __END__
« SSI/Common.pm ↑ Summary