1Mixin::Linewise::ReaderUss(e3r)Contributed Perl DocumentMaitxiionn::Linewise::Readers(3)
2
3
4
6 Mixin::Linewise::Readers - get linewise readers for strings and
7 filenames
8
10 version 0.108
11
13 package Your::Pkg;
14 use Mixin::Linewise::Readers -readers;
15
16 sub read_handle {
17 my ($self, $handle) = @_;
18
19 LINE: while (my $line = $handle->getline) {
20 next LINE if $line =~ /^#/;
21
22 print "non-comment: $line";
23 }
24 }
25
26 Then:
27
28 use Your::Pkg;
29
30 Your::Pkg->read_file($filename);
31
32 Your::Pkg->read_string($string);
33
34 Your::Pkg->read_handle($fh);
35
37 "read_file" and "read_string" are exported by default. Either can be
38 requested individually, or renamed. They are generated by
39 Sub::Exporter, so consult its documentation for more information.
40
41 Both can be generated with the option "method" which requests that a
42 method other than "read_handle" is called with the created IO::Handle.
43
44 If given a "binmode" option, any "read_file" type functions will use
45 that as an IO layer, otherwise, the default is "utf8_strict".
46
47 use Mixin::Linewise::Readers -readers => { binmode => "raw" };
48 use Mixin::Linewise::Readers -readers => { binmode => "encoding(iso-8859-1)" };
49
50 read_file
51 Your::Pkg->read_file($filename);
52 Your::Pkg->read_file(\%options, $filename);
53
54 If generated, the "read_file" export attempts to open the named file
55 for reading, and then calls "read_handle" on the opened handle.
56
57 An optional hash reference may be passed before $filename with options.
58 The only valid option currently is "binmode", which overrides any
59 default set from "use" or the built-in "utf8_strict".
60
61 Any arguments after $filename are passed along after to "read_handle".
62
63 read_string
64 Your::Pkg->read_string($string);
65 Your::Pkg->read_string(\%option, $string);
66
67 If generated, the "read_string" creates a handle on the given string,
68 and then calls "read_handle" on the opened handle. Because handles on
69 strings must be octet-oriented, the string must contain octets. It
70 will be opened in the default binmode established by importing. (See
71 "EXPORTS", above.)
72
73 Any arguments after $string are passed along after to "read_handle".
74
75 Like "read_file", this method can take a leading hashref with one valid
76 argument: "binmode".
77
79 Ricardo SIGNES <rjbs@cpan.org>
80
82 This software is copyright (c) 2008 by Ricardo SIGNES.
83
84 This is free software; you can redistribute it and/or modify it under
85 the same terms as the Perl 5 programming language system itself.
86
87
88
89perl v5.32.1 2021-01-27 Mixin::Linewise::Readers(3)