Dpkg/File.pm

filter: Statementstmt 100% 43 / 43 Branchbran 75.0% 15 / 20 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 8 / 8 Podpod 0.0% 0 / 3 totaltotal 89.1% 66 / 74 CC 11 SCAR 12.7
CC
11
Cov
92%
file_dump
5.0
file_touch
4.4
file_slurp
4.0
CRAP 3.5
« Dpkg/Dist/Files.pm ↑ Summary Dpkg/BuildProfiles.pm »
1 # Copyright © 2011 Raphaël Hertzog <hertzog@debian.org>
2 # Copyright © 2012 Guillem Jover <guillem@debian.org>
3 #
4 # This program is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 2 of the License, or
7 # (at your option) any later version.
8 #
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License
15 # along with this program. If not, see <https://www.gnu.org/licenses/>.
16  
17 =encoding utf8
18  
19 =head1 NAME
20  
21 Dpkg::File - file handling
22  
23 =head1 DESCRIPTION
24  
25 This module provides file handling support functions.
26  
27 B<Note>: This is a private module, its API can change at any time.
28  
29 =cut
30  
31 package Dpkg::File 0.01;
32  
33 25 ▶use v5.36;
Subroutine BEGIN: called CC=1 SCAR=0.0
34  
35 23 our @EXPORT = qw(
36 file_slurp
37 file_dump
38 file_touch
39 );
40  
41 25 ▶use Exporter qw(import);
Subroutine BEGIN: called CC=1 SCAR=0.0
42 25 ▶use Scalar::Util qw(openhandle);
Subroutine BEGIN: called CC=1 SCAR=0.0
43  
44 25 ▶use Dpkg::ErrorHandling;
Subroutine BEGIN: called CC=1 SCAR=0.0
45 25 ▶use Dpkg::Gettext;
Subroutine BEGIN: called CC=1 SCAR=0.0
46  
47 40 ▶sub file_slurp {
Subroutine file_slurp: called CC=4 SCAR=13.9
Pod undocumented
48 40 my $file = shift;
49 40 my $fh;
50 40 my $doclose = 0;
51  
52 40 ▶ if (openhandle($file)) {
Branch: 1 branch
BranchTrueFalseTotal
if (&openhandle($file)) { } 5 35 40
53 5 $fh = $file;
54 } else {
55 35 ▶ open $fh, '<', $file or syserr(g_('cannot read %s'), $fh);
Branch: 1 branch
BranchTrueFalseTotal
open $fh, "<", $file or syserr(g_("cannot read %s"), $fh) 34 1 35
56 34 $doclose = 1;
57 }
58 39 local $/;
59 39 my $data = <$fh>;
60 39 ▶ close $fh if $doclose;
Branch: 1 branch
BranchTrueFalseTotal
if $doclose 34 5 39
61  
62 39 return $data;
63 }
64  
65 38 ▶sub file_dump {
Subroutine file_dump: called CC=5 SCAR=16.1
Pod undocumented
66 38 my ($file, $data) = @_;
67 38 my $fh;
68 38 my $doclose = 0;
69  
70 38 ▶ if (openhandle($file)) {
Branch: 1 branch
BranchTrueFalseTotal
if (&openhandle($file)) { } 15 23 38
71 15 $fh = $file;
72 } else {
73 23 ▶ open $fh, '>', $file or syserr(g_('cannot create file %s'), $file);
Branch: 1 branch
BranchTrueFalseTotal
open $fh, ">", $file or syserr(g_("cannot create file %s"), $file) 23 0 23
74 23 $doclose = 1;
75 }
76 38 print { $fh } $data;
77 38 ▶ if ($doclose) {
Branch: 1 branch
BranchTrueFalseTotal
if ($doclose) 23 15 38
78 23 ▶ close $fh or syserr(g_('cannot write %s'), $file);
Branch: 1 branch
BranchTrueFalseTotal
close $fh or syserr(g_("cannot write %s"), $file) 23 0 23
79 }
80  
81 38 return;
82 }
83  
84 75 ▶sub file_touch {
Subroutine file_touch: called CC=4 SCAR=14.9
Pod undocumented
85 75 my $file = shift;
86  
87 75 ▶ open my $fh, '>>', $file
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, ">>", $file or syserr(g_("cannot touch file %s"), $file) 75 0 75
88 or syserr(g_('cannot touch file %s'), $file);
89 75 ▶ close $fh or syserr(g_('cannot write %s'), $file);
Branch: 1 branch
BranchTrueFalseTotal
close $fh or syserr(g_("cannot write %s"), $file) 75 0 75
90 75 ▶ utime undef, undef, $file
Branch: 1 branch
BranchTrueFalseTotal
utime undef, undef, $file or syserr(g_("cannot change timestamp for %s"), $file) 75 0 75
91 or syserr(g_('cannot change timestamp for %s'), $file);
92 }
93  
94 =head1 CHANGES
95  
96 =head2 Version 0.xx
97  
98 This is a private module.
99  
100 =cut
101  
102 23 1;
« Dpkg/Dist/Files.pm ↑ Summary Dpkg/BuildProfiles.pm »