Ticket #117: slurp.functions.txt

File slurp.functions.txt, 1.4 KB (added by jkeenan, 6 years ago)

Our 5 different slurp functions.

Line 
1Parrot::BuildUtil::slurp_file
2
3sub slurp_file {
4    my ($file_name) = @_;
5
6    open( my $SLURP, '<', $file_name ) or die "open '$file_name': $!";
7    local $/ = undef;
8    my $file = <$SLURP> . '';
9    $file =~ s/\cM\cJ/\n/g;
10    close $SLURP;
11
12    return $file;
13}
14
15Parrot::Test::slurp_file
16
17sub slurp_file {
18    my ($file_name) = @_;
19
20    open( my $SLURP, '<', $file_name ) or die "open '$file_name': $!";
21    local $/ = undef;
22    my $file = <$SLURP> . '';
23    $file    =~ s/\cM\cJ/\n/g;
24    close $SLURP;
25
26    return $file;
27}
28
29Parrot::Configure::Utils::_slurp
30
31sub _slurp {
32    my $filename = shift;
33
34    open( my $fh, '<', $filename ) or die "Can't open $filename: $!";
35    my $text = do { local $/; <$fh> };
36    close($fh) or die "Can't close $filename: $!";
37
38    return $text;
39}
40
41Parrot::Distribution::slurp
42
43sub slurp {
44    my $self = shift;
45    my $path = shift;
46    my $buf;
47
48    # slurp in the file
49    open( my $fh, '<', $path )
50        or die "Cannot open '$path' for reading: $!\n";
51    {
52        local $/;
53        $buf = <$fh>;
54    }
55    close $fh;
56
57    return $buf;
58}
59
60
61tools/util/dump_pbc.pl
62
63sub slurp_file {
64    my $file = shift;
65    my $source;
66
67       open $source, '<', $file
68    or open $source, '<', "$PARROT_ROOT/$file"
69    or open $source, '<', "$RUNTIME_DIR/$file"
70    or die "Could not open source file '$file': $!";
71
72    my @lines = <$source>;
73
74    return \@lines;
75}
76
77