1Mixin::Linewise::WriterUss(e3r)Contributed Perl DocumentMaitxiionn::Linewise::Writers(3)
2
3
4
6 Mixin::Linewise::Writers - get linewise writers for strings and
7 filenames
8
10 version 0.110
11
13 package Your::Pkg;
14 use Mixin::Linewise::Writers -writers;
15
16 sub write_handle {
17 my ($self, $data, $handle) = @_;
18
19 $handle->print("datum: $_\n") for @$data;
20 }
21
22 Then:
23
24 use Your::Pkg;
25
26 Your::Pkg->write_file($data, $filename);
27
28 Your::Pkg->write_string($data, $string);
29
30 Your::Pkg->write_handle($data, $fh);
31
33 This module has the same support period as perl itself: it supports
34 the two most recent versions of perl. (That is, if the most recently
35 released version is v5.40, then this module should work on both v5.40
36 and v5.38.)
37
38 Although it may work on older versions of perl, no guarantee is made
39 that the minimum required version will not be increased. The version
40 may be increased for any reason, and there is no promise that patches
41 will be accepted to lower the minimum required perl.
42
44 "write_file" and "write_string" are exported by default. Either can be
45 requested individually, or renamed. They are generated by
46 Sub::Exporter, so consult its documentation for more information.
47
48 Both can be generated with the option "method" which requests that a
49 method other than "write_handle" is called with the created IO::Handle.
50
51 If given a "binmode" option, any "write_file" type functions will use
52 that as an IO layer, otherwise, the default is "encoding(UTF-8)".
53
54 use Mixin::Linewise::Writers -writers => { binmode => "raw" };
55 use Mixin::Linewise::Writers -writers => { binmode => "encoding(iso-8859-1)" };
56
57 write_file
58 Your::Pkg->write_file($data, $filename);
59 Your::Pkg->write_file($data, $options, $filename);
60
61 This method will try to open a new file with the given name. It will
62 then call "write_handle" with that handle.
63
64 An optional hash reference may be passed before $filename with options.
65 The only valid option currently is "binmode", which overrides any
66 default set from "use" or the built-in "encoding(UTF-8)".
67
68 Any arguments after $filename are passed along after to "write_handle".
69
70 write_string
71 my $string = Your::Pkg->write_string($data);
72 my $string = Your::Pkg->write_string(\%option, $data);
73
74 "write_string" will create a new handle on the given string, then call
75 "write_handle" to write to that handle, and return the resulting
76 string. Because handles on strings must be octet-oriented, the string
77 will contain octets. It will be opened in the default binmode
78 established by importing. (See "EXPORTS", above, and the options,
79 below.)
80
81 Any arguments after $data are passed along after to "write_handle".
82
83 Like "write_file", this method can take a leading hashref with one
84 valid argument: "binmode".
85
87 Ricardo SIGNES <rjbs@semiotic.systems>
88
90 This software is copyright (c) 2008 by Ricardo SIGNES.
91
92 This is free software; you can redistribute it and/or modify it under
93 the same terms as the Perl 5 programming language system itself.
94
95
96
97perl v5.36.0 2022-07-22 Mixin::Linewise::Writers(3)