Flute/Utils.pm

filter: Statementstmt 61.9% 13 / 21 Branchbran 0.0% 0 / 4 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 80.0% 4 / 5 Podpod 100% 1 / 1 totaltotal 50.0% 18 / 36 CC 4 SCAR 23.5
CC
4
Cov
46%
derive_filename
20.0
BEGIN
1.0
BEGIN
1.0
CRAP 10.5
« Flute/List.pm ↑ Summary Flute/Iterator/Cache.pm »
1 package Template::Flute::Utils;
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 1 ▶use File::Basename;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use File::Spec;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 =head1 NAME
10  
11 Template::Flute::Utils - Template::Flute utility functions
12  
13 =head1 FUNCTIONS
14  
15 =head2 derive_filename FILENAME SUFFIX [FULL] [ARGS]
16  
17 Derives a filename with a different SUFFIX from FILENAME, e.g.
18  
19 derive_filename('templates/helloworld.html', '.xml')
20  
21 returns
22  
23 templates/helloworld.xml
24  
25 With the FULL parameter set it can be used to produce a path
26 for a relative filename from another filename with a directory,
27 e.g.
28  
29 derive_filename('templates/helloworld.html', 'foobar.png', 1)
30  
31 returns
32  
33 templates/foobar.png
34  
35 Also, with the C<pass_absolute> argument a SUFFIX containing
36 an absolute file path will be returned verbatim, e.g.
37  
38 derive_filename('templates/helloword.html',
39 '/home/racke/components/login.html',
40 1,
41 pass_absolute => 1)
42  
43 produces
44  
45 /home/racke/components/login.html
46  
47 =cut
48  
49 sub derive_filename {
50 0 ▶ my ($orig_filename, $suffix, $full, %args) = @_;
Subroutine derive_filename: not called CC=4 SCAR=30.0
Pod documented
51 0 my ($orig_dir, @frags);
52  
53 0 ▶ if ($args{pass_absolute} && File::Spec->file_name_is_absolute($suffix)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args{"pass_absolute"} and "File::Spec"->file_name_is_absolute($suffix)) 0 0 0
Condition0%0/3
$args{"pass_absolute"} and "File::Spec"->file_name_is_absolute($suffix)
!ll&&!rl&&r
000
MC/DC0%0/2
$args{"pass_absolute"} and "File::Spec"->file_name_is_absolute($suffix)
$args{"pass_absolute"} "File::Spec"->file_name_is_absolute($suffix)
Truth table0%0/3
A and B
A= $args{"pass_absolute"}B= "File::Spec"->file_name_is_absolute($suffix)
ABresult
0X0
100
111
54 # pass through suffixes with absolute file paths
55 0 return $suffix;
56 }
57
58 0 @frags = fileparse($orig_filename, qr/\.[^.]*/);
59  
60 0 ▶ if ($full) {
Branch: 1 branch
BranchTrueFalseTotal
if ($full) { } 0 0 0
61 0 return $frags[1] . $suffix;
62 }
63 else {
64 0 return $frags[1] . $frags[0] . $suffix;
65 }
66 }
67  
68 =head1 AUTHOR
69  
70 Stefan Hornburg (Racke), <racke@linuxia.de>
71  
72 =head1 LICENSE AND COPYRIGHT
73  
74 Copyright 2010-2016 Stefan Hornburg (Racke) <racke@linuxia.de>.
75  
76 This program is free software; you can redistribute it and/or modify it
77 under the terms of either: the GNU General Public License as published
78 by the Free Software Foundation; or the Artistic License.
79  
80 See http://dev.perl.org/licenses/ for more information.
81  
82 =cut
83  
84 1 1;
« Flute/List.pm ↑ Summary Flute/Iterator/Cache.pm »