Debian Codegraph @

t/lib/Config/IniFiles/Slurp.pm

raw symbols SCIP
1 package Config::IniFiles::Slurp;
2
3 use strict;
4 use warnings;
5
6 use File::Spec;
7
8 use parent 'Exporter';
9
10 use vars (qw(@EXPORT_OK));
11
12 @EXPORT_OK = (qw( bin_slurp slurp utf8_slurp utf8_spew ));
13
14 =head2 slurp()
15
16 Reads the entire file.
17
18 =cut
19
20 sub slurp
21 {
22 my $filename = shift;
23
24 open my $in, '<', $filename
25 or die "Cannot open '$filename' for slurping - $!";
26
27 local $/;
28 my $contents = <$in>;
29
30 close($in);
31
32 return $contents;
33 }
34
35 =head2 slurp()
36
37 Reads the entire file with binmode
38
39 =cut
40
41 sub bin_slurp
42 {
43 my $filename = shift;
44
45 open my $in, '<', $filename
46 or die "Cannot open '$filename' for slurping - $!";
47
48 binmode $in;
49 local $/;
50 my $contents = <$in>;
51
52 close($in);
53
54 return $contents;
55 }
56
57 sub utf8_slurp
58 {
59 my $filename = shift;
60
61 open my $in, '<:encoding(utf8)', $filename
62 or die "Cannot open '$filename' for slurping - $!";
63
64 local $/;
65 my $contents = <$in>;
66
67 close($in);
68
69 return $contents;
70 }
71
72 sub utf8_spew
73 {
74 my $filename = shift;
75
76 open my $out, '>:encoding(utf8)', $filename
77 or die "Cannot open '$filename' for spewing - $!";
78
79 print {$out} @_;
80
81 close($out);
82
83 return;
84 }
85
86 1;