line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package MooseX::Types::IO; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
47447
|
use warnings; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
65
|
|
4
|
2
|
|
|
2
|
|
10
|
use strict; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
117
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our $VERSION = '0.04'; |
7
|
|
|
|
|
|
|
our $AUTHORITY = 'cpan:FAYLAND'; |
8
|
|
|
|
|
|
|
|
9
|
2
|
|
|
2
|
|
1737
|
use IO qw/File Handle/; |
|
2
|
|
|
|
|
1741
|
|
|
2
|
|
|
|
|
11
|
|
10
|
2
|
|
|
2
|
|
26331
|
use IO::String; |
|
2
|
|
|
|
|
5890
|
|
|
2
|
|
|
|
|
82
|
|
11
|
|
|
|
|
|
|
|
12
|
2
|
|
|
2
|
|
2234
|
use MooseX::Types::Moose qw/Str ScalarRef FileHandle ArrayRef Object/; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
use namespace::clean; |
14
|
|
|
|
|
|
|
use MooseX::Types -declare => [qw( IO )]; |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
subtype IO, as Object; |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
coerce IO, |
19
|
|
|
|
|
|
|
from Str, |
20
|
|
|
|
|
|
|
via { |
21
|
|
|
|
|
|
|
my $fh = new IO::File; $fh->open($_); return $fh; |
22
|
|
|
|
|
|
|
}, |
23
|
|
|
|
|
|
|
from ScalarRef, |
24
|
|
|
|
|
|
|
via { |
25
|
|
|
|
|
|
|
IO::String->new($$_); |
26
|
|
|
|
|
|
|
}, |
27
|
|
|
|
|
|
|
from ArrayRef[FileHandle|Str], |
28
|
|
|
|
|
|
|
via { |
29
|
|
|
|
|
|
|
IO::Handle->new_from_fd( @$_ ); |
30
|
|
|
|
|
|
|
}; |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
require MooseX::Types::IO_Global; |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
1; |
35
|
|
|
|
|
|
|
__END__ |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
=head1 NAME |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
MooseX::Types::IO - L<IO> related constraints and coercions for Moose |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
=head1 SYNOPSIS |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
package Foo; |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
use Moose; |
46
|
|
|
|
|
|
|
use MooseX::Types::IO 'IO'; |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
has io => ( |
49
|
|
|
|
|
|
|
isa => IO, |
50
|
|
|
|
|
|
|
is => "rw", |
51
|
|
|
|
|
|
|
coerce => 1, |
52
|
|
|
|
|
|
|
); |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
# later |
55
|
|
|
|
|
|
|
my $str = "test for IO::String\n line 2"; |
56
|
|
|
|
|
|
|
my $foo = Foo->new( io => \$str ); |
57
|
|
|
|
|
|
|
my $io = $foo->io; # IO::String |
58
|
|
|
|
|
|
|
# or |
59
|
|
|
|
|
|
|
my $filename = "file.txt"; |
60
|
|
|
|
|
|
|
my $foo = Foo->new( io => $filename ); |
61
|
|
|
|
|
|
|
my $io = $foo->io; # IO::File |
62
|
|
|
|
|
|
|
# or |
63
|
|
|
|
|
|
|
my $foo = Foo->new( io => [ $fh, '<' ] ); |
64
|
|
|
|
|
|
|
my $io = $foo->io; # IO::Handle |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
=head1 DESCRIPTION |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
This module packages one L<Moose::Util::TypeConstraints> with coercions, |
69
|
|
|
|
|
|
|
designed to work with the L<IO> suite of objects. |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
=head1 CONSTRAINTS |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
=over 4 |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
=item B<Str> |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
my $fh = new IO::File; |
78
|
|
|
|
|
|
|
$fh->open($_); |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
L<IO::File> object. |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
=item B<ScalarRef> |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
IO::String->new($$_); |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
L<IO::String> object. |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
=item B<ArrayRef[FileHandle|Str]> |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
IO::Handle->new_from_fd( @$_ ); |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
L<IO::Handle> object. |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
=back |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
=head1 SEE ALSO |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
L<Moose>, L<MooseX::Types>, L<MooseX::Types::IO::All>, L<IO::Hanlde>, L<IO::File>, L<IO::String> |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
=head1 AUTHOR |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
Fayland Lam, C<< <fayland at gmail.com> >> |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
=head1 ACKNOWLEDGEMENTS |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
The L<Moose> Team |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
Rafael Kitover (rkitover) for the patches on RT 46194 |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
=head1 COPYRIGHT & LICENSE |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
Copyright 2008 Fayland Lam, all rights reserved. |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it |
115
|
|
|
|
|
|
|
under the same terms as Perl itself. |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
=cut |