Get IO::CatHandle's current handle's line number
Other
Switch branches/tags
Nothing to show
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
lib/IO/CatHandle
logotype
t
.gitignore
.travis.yml
LICENSE
META6.json
README.md

README.md

Build Status

NAME

IO::CatHandle::AutoLines - Get IO::CatHandle's current handle's line number

SYNOPSIS

    use IO::CatHandle::AutoLines;

    'some'   .IO.spurt: "a\nb\nc";
    'files'  .IO.spurt: "d\ne\nf";
    'to-read'.IO.spurt: "g\nh";

    my $kitty = IO::CatHandle.new(<some files to-read>, :on-switch{
        say "Meow!"
    }) does IO::CatHandle::AutoLines;

    say "$kitty.ln(): $_" for $kitty.lines;

    # OUTPUT:
    # Meow!
    # 1: a
    # 2: b
    # 3: c
    # Meow!
    # 1: d
    # 2: e
    # 3: f
    # Meow!
    # 1: g
    # 2: h
    # Meow!

DESCRIPTION

A role that adds .ln method to IO::CatHandle type that will contain the current line number. Optionally, the lines counter can be reset when next source handle get switched into.

Note: only .lines and .get methods are overriden to increment the line counter. Using any other methods to read data will not increment the line counter.

EXPORTED TYPES

role IO::CatHandle::AutoLines

Defined as:

    role IO::CatHandle::AutoLines[Bool:D :$reset = True]

Provides .ln method containing Int:D of the current line number. If :$reset parameter is set to True (default), then on source handle switch, the line number will be reset back to zero.

    # Reset on-switch enabled
    my $cat1 = IO::CatHandle.new(…) does role IO::CatHandle::AutoLines;

    # Reset on-switch disabled
    my $cat2 = IO::CatHandle.new(…) does role IO::CatHandle::AutoLines[:!reset];

REPOSITORY

Fork this module on GitHub: https://github.com/zoffixznet/perl6-IO-CatHandle-AutoLines

BUGS

To report bugs or request features, please use https://github.com/zoffixznet/perl6-IO-CatHandle-AutoLines/issues

AUTHOR

Zoffix Znet (http://perl6.party/)

LICENSE

You can use and distribute this module under the terms of the The Artistic License 2.0. See the LICENSE file included in this distribution for complete details.

The META6.json file of this distribution may be distributed and modified without restrictions or attribution.