line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package File::Glob::Slurp; |
2
|
1
|
|
|
1
|
|
21442
|
use 5.008001; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
33
|
|
3
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
24
|
|
4
|
1
|
|
|
1
|
|
5
|
use strict; |
|
1
|
|
|
|
|
6
|
|
|
1
|
|
|
|
|
71
|
|
5
|
|
|
|
|
|
|
our $VERSION = sprintf "%d.%02d", q$Revision: 0.2 $ =~ /(\d+)/g; |
6
|
1
|
|
|
1
|
|
5
|
use Carp; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
84
|
|
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
5
|
no warnings 'redefine'; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
270
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
*CORE::GLOBAL::glob = sub { |
11
|
0
|
|
|
0
|
|
|
my $path = shift; |
12
|
0
|
|
|
|
|
|
$path =~ s/\A\s+//; |
13
|
0
|
|
|
|
|
|
$path =~ s/\s+\z//; |
14
|
0
|
|
|
|
|
|
my $slurp; |
15
|
0
|
0
|
|
|
|
|
if ( $path =~ m{\w+://} ) { |
16
|
0
|
|
|
|
|
|
eval { require LWP::Simple; }; |
|
0
|
|
|
|
|
|
|
17
|
0
|
0
|
|
|
|
|
croak $@ if $@; |
18
|
0
|
|
|
|
|
|
$slurp = LWP::Simple::get($path); |
19
|
|
|
|
|
|
|
} |
20
|
|
|
|
|
|
|
else { |
21
|
0
|
|
|
|
|
|
local $/; |
22
|
0
|
0
|
|
|
|
|
open my $fh, '<', $path or croak "$path:$!"; |
23
|
0
|
|
|
|
|
|
$slurp = CORE::readline($fh); |
24
|
0
|
|
|
|
|
|
close $fh; |
25
|
|
|
|
|
|
|
} |
26
|
0
|
|
|
|
|
|
return $slurp; |
27
|
|
|
|
|
|
|
}; |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
if ($0 eq __FILE__){ |
30
|
|
|
|
|
|
|
my $content = ; |
31
|
|
|
|
|
|
|
print $content; |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
1; # End of File::Glob::Slurp |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
=head1 NAME |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
File::Glob::Slurp - Turns <> into a slurp operator |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
=head1 VERSION |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
$Id: Slurp.pm,v 0.2 2009/06/10 05:51:19 dankogai Exp dankogai $ |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
=head1 SYNOPSIS |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
Quick summary of what the module does. |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
Perhaps a little code snippet. |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
use File::Glob::Slurp; |
51
|
|
|
|
|
|
|
# slurps path/to/filename.ext |
52
|
|
|
|
|
|
|
my $home = ; |
53
|
|
|
|
|
|
|
# you can do this if you have LWP::Simple |
54
|
|
|
|
|
|
|
my $away = ; |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
=head1 EXPORT |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
tweaks C |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
=head1 DESCRIPTION |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
HACK #90 of PERL HACK proved that C<< <*glob*> >> operator is a pretty |
63
|
|
|
|
|
|
|
good place to implement micro-DSL. This module turns ancient |
64
|
|
|
|
|
|
|
C<< *glob* >> operator into modern C<< slurp >> operator! |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
As shown in L, The overridden C<< <> >> slurps not only |
67
|
|
|
|
|
|
|
local files but also URL if you have L installed. |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
=head2 CAVEAT |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
Unfortunately C<< <> >> also acts as C. Therefore |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
my $content = <$path>; |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
Does not work. In such cases simply add whitespece like: |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
my $content = < $path >; |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
=head1 AUTHOR |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
Dan Kogai, C<< >> |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
=head1 BUGS |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
Please report any bugs or feature requests to C, or through |
86
|
|
|
|
|
|
|
the web interface at L. I will be notified, and then you'll |
87
|
|
|
|
|
|
|
automatically be notified of progress on your bug as I make changes. |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
=head1 SUPPORT |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
You can find documentation for this module with the perldoc command. |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
perldoc File::Glob::Slurp |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
You can also look for information at: |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
=over 4 |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
=item * RT: CPAN's request tracker |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
L |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
=item * AnnoCPAN: Annotated CPAN documentation |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
L |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
=item * CPAN Ratings |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
L |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
=item * Search CPAN |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
L |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
=back |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
=head1 ACKNOWLEDGEMENTS |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
Hack #90 of Perl Hacks L |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
L |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
=head1 COPYRIGHT & LICENSE |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
Copyright 2009 Dan Kogai, all rights reserved. |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it |
128
|
|
|
|
|
|
|
under the same terms as Perl itself. |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
=cut |