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   72320 use strict;
  3         14  
  3         86  
20 3     3   28 use warnings;
  3         6  
  3         168  
21              
22             our $VERSION = '0.01';
23             our @EXPORT = qw(
24             file_slurp
25             );
26              
27 3     3   17 use Exporter qw(import);
  3         5  
  3         114  
28 3     3   18 use Scalar::Util qw(openhandle);
  3         4  
  3         154  
29              
30 3     3   1300 use Dpkg::ErrorHandling;
  3         10  
  3         224  
31 3     3   20 use Dpkg::Gettext;
  3         6  
  3         461  
32              
33             sub file_slurp {
34 16     16 0 116 my $file = shift;
35 16         26 my $fh;
36 16         29 my $doclose = 0;
37              
38 16 100       68 if (openhandle($file)) {
39 4         11 $fh = $file;
40             } else {
41 12 50       548 open $fh, '<', $file or syserr(g_('cannot read %s'), $fh);
42 12         50 $doclose = 1;
43             }
44 16         76 local $/;
45 16         551 my $data = <$fh>;
46 16 100       311 close $fh if $doclose;
47              
48 16         153 return $data;
49             }
50              
51             1;