| MooseX-Types-IO documentation | Contained in the MooseX-Types-IO distribution. |
MooseX::Types::IO::All - IO::All related constraints and coercions for Moose
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
This module packages one Moose::Util::TypeConstraints with coercions, designed to work with the IO::All suite of objects.
io $_;
IO::All object.
my $s = io('$');
$s->print($$_);
IO::All::String object. so generally u need
${ $s->string_ref } # the content
instead of ->all or ->slurp
Fayland Lam, <fayland at gmail.com>
The Moose Team
Copyright 2008 Fayland Lam, all rights reserved.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
| 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__