Mixin::Linewise::Readers(3) User Contributed Perl Documentation Mixin::Linewise::Readers(3)

# [SYNOPSIS](#SYNOPSIS)

```
  package Your::Pkg;
  use Mixin::Linewise::Readers -readers;
  sub read_handle {
    my ($self, $handle) = @_;
    LINE: while (my $line = $handle->getline) {
      next LINE if $line =~ /^#/;
      print "non-comment: $line";
    }
  }
```

Then:

```
  use Your::Pkg;
  Your::Pkg->read_file($filename);
  Your::Pkg->read_string($string);
  Your::Pkg->read_handle($fh);
```

# [EXPORTS](#EXPORTS)

"read\_file" and "read\_string" are exported by default. Either can be requested individually, or renamed. They are generated by Sub::Exporter, so consult its documentation for more information.

Both can be generated with the option "method" which requests that a method other than "read\_handle" is called with the created IO::Handle.

If given a "binmode" option, any "read\_file" type functions will use that as an IO layer, otherwise, the default is "utf8\_strict".

```
  use Mixin::Linewise::Readers -readers => { binmode => "raw" };
  use Mixin::Linewise::Readers -readers => { binmode => "encoding(iso-8859-1)" };
```

## [read\_file](#read_file)

```
  Your::Pkg->read_file($filename);
  Your::Pkg->read_file(\%options, $filename);
```

If generated, the "read\_file" export attempts to open the named file for reading, and then calls "read\_handle" on the opened handle.

An optional hash reference may be passed before $filename with options. The only valid option currently is "binmode", which overrides any default set from "use" or the built-in "utf8\_strict".

Any arguments after $filename are passed along after to "read\_handle".

## [read\_string](#read_string)

```
  Your::Pkg->read_string($string);
  Your::Pkg->read_string(\%option, $string);
```

If generated, the "read\_string" creates a handle on the given string, and then calls "read\_handle" on the opened handle. Because handles on strings must be octet-oriented, the string **must contain octets**. It will be opened in the default binmode established by importing. (See "EXPORTS", above.)

Any arguments after $string are passed along after to "read\_handle".

Like "read\_file", this method can take a leading hashref with one valid argument: "binmode".

2026-10-26 perl v5.44.0

---

Document: Mixin::Linewise::Readers(3pm) from perl-mixin-linewise 0.111-r5 (Chainguard OS)
Source: https://github.com/rjbs/Mixin-Linewise
