MooseX::Types::IO::All - L<IO::All> related constraints and coercions for Moose


MooseX-Types-IO documentation Contained in the MooseX-Types-IO distribution.

Index


Code Index:

NAME

Top

MooseX::Types::IO::All - IO::All related constraints and coercions for Moose

SYNOPSIS

Top

    package Foo;

    use Moose;
    use MooseX::Types::IO::All 'IO_All';

    has io => (
        isa => IO_All,
        is  => "rw",
        coerce => 1,
    );

    # later
    my $str = "test for IO::String\n line 2";
    my $foo = Foo->new( io => \$str );
    my $io  = $foo->io; # IO::All::String
    # or
    my $filename = "file.txt";
    my $foo = Foo->new( io => $filename );
    my $io  = $foo->io; # IO::All

DESCRIPTION

Top

This module packages one Moose::Util::TypeConstraints with coercions, designed to work with the IO::All suite of objects.

CONSTRAINTS

Top

Str
    io $_;

IO::All object.

ScalarRef
    my $s = io('$');
    $s->print($$_);

IO::All::String object. so generally u need

    ${ $s->string_ref } # the content

instead of ->all or ->slurp

SEE ALSO

Top

Moose, MooseX::Types, MooseX::Types::IO, IO::All

AUTHOR

Top

Fayland Lam, <fayland at gmail.com>

ACKNOWLEDGEMENTS

Top

The Moose Team

COPYRIGHT & LICENSE

Top


MooseX-Types-IO documentation Contained in the MooseX-Types-IO distribution.

package MooseX::Types::IO::All;

use warnings;
use strict;

our $VERSION   = '0.03';
our $AUTHORITY = 'cpan:FAYLAND';

use IO::All;

use MooseX::Types::Moose qw/Str ScalarRef FileHandle ArrayRef/;
use namespace::clean;
use MooseX::Types -declare => [qw( IO_All )];

my $global = class_type 'IO::All';
subtype IO_All, as 'IO::All';

coerce IO_All,
    from Str,
        via {
            io $_;
        },
    from ScalarRef,
        via {
            my $s = io('$');
            $s->print($$_);
            return $s;
        };

$global->coercion(IO_All->coercion);

1;
__END__