File Coverage

blib/lib/Dpkg/File.pm
Criterion Covered Total %
statement 29 29 100.0
branch 5 6 83.3
condition n/a
subroutine 7 7 100.0
pod 0 1 0.0
total 41 43 95.3


line stmt bran cond sub pod time code
1             # Copyright © 2011 Raphaël Hertzog
2             # Copyright © 2012 Guillem Jover
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 .
16              
17             package Dpkg::File;
18              
19 3     3   74813 use strict;
  3         16  
  3         90  
20 3     3   32 use warnings;
  3         6  
  3         182  
21              
22             our $VERSION = '0.01';
23             our @EXPORT = qw(
24             file_slurp
25             );
26              
27 3     3   18 use Exporter qw(import);
  3         6  
  3         119  
28 3     3   19 use Scalar::Util qw(openhandle);
  3         6  
  3         161  
29              
30 3     3   1269 use Dpkg::ErrorHandling;
  3         10  
  3         229  
31 3     3   20 use Dpkg::Gettext;
  3         6  
  3         472  
32              
33             sub file_slurp {
34 16     16 0 74 my $file = shift;
35 16         24 my $fh;
36 16         31 my $doclose = 0;
37              
38 16 100       62 if (openhandle($file)) {
39 4         8 $fh = $file;
40             } else {
41 12 50       594 open $fh, '<', $file or syserr(g_('cannot read %s'), $fh);
42 12         50 $doclose = 1;
43             }
44 16         74 local $/;
45 16         572 my $data = <$fh>;
46 16 100       320 close $fh if $doclose;
47              
48 16         150 return $data;
49             }
50              
51             1;