Skip to content

Commit a404865

Browse files
committed
Add docs for IO::ArgFiles
1 parent a34c050 commit a404865

File tree

1 file changed

+69
-0
lines changed

1 file changed

+69
-0
lines changed

lib/Type/IO/ArgFiles.pm

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
=begin pod
2+
3+
=TITLE class IO::ArgFiles
4+
5+
=SUBTITLE Iterate over contents of files specified on command line
6+
7+
class IO::ArgFiles is IO::Handle { }
8+
9+
If command line arguments are provided, take them as file names and iterate
10+
over the contents of the files. If no arguments are specified, process
11+
standard input.
12+
13+
One could print the lines of the files specified on the command line to
14+
standard output using code such as this:
15+
16+
use v6;
17+
18+
my $argfiles = IO::ArgFiles.new(args => @*ARGS);
19+
20+
.say for $argfiles.lines;
21+
22+
Or equivalently by using the C<eof> and C<get> methods:
23+
24+
use v6;
25+
26+
my $argfiles = IO::ArgFiles.new(args => @*ARGS);
27+
28+
while ! $argfiles.eof {
29+
say $argfiles.get;
30+
}
31+
32+
Here's the same thing via the C<slurp> method:
33+
34+
use v6;
35+
36+
my $argfiles = IO::ArgFiles.new(args => @*ARGS);
37+
38+
say $argfiles.slurp;
39+
40+
=head1 Methods
41+
42+
=head2 method eof
43+
44+
Return C<True> if the end of the file has been reached, otherwise C<False>.
45+
46+
=head2 method get
47+
48+
Return one line of the open file handle.
49+
50+
=head2 method lines
51+
52+
Return a (lazy) list of the remaining lines in the file pointed to by the
53+
file handle.
54+
55+
=head2 method slurp
56+
57+
Slurp the entire contents of the file into a string.
58+
59+
=head2 method nl
60+
61+
The newline character for the file. By default this is C<\n>.
62+
63+
=head1 Related roles and classes
64+
65+
See also the related role L<IO> and the related class L<IO::Handle>.
66+
67+
=end pod
68+
69+
# vim: expandtab shiftwidth=4 ft=perl6

0 commit comments

Comments
 (0)