| 1 | #!/usr/bin/perl -c | ||
| 2 | |||
| 3 | package IO::Moose; | ||
| 4 | |||
| 5 | =head1 NAME | ||
| 6 | |||
| 7 | IO::Moose - Reimplementation of IO::* with improvements | ||
| 8 | |||
| 9 | =head1 SYNOPSIS | ||
| 10 | |||
| 11 | use IO::Moose 'Handle', 'File'; # loads IO::Moose::* modules | ||
| 12 | |||
| 13 | $passwd = IO::Moose::File->new( file => '/etc/passwd' )->slurp; | ||
| 14 | |||
| 15 | =head1 DESCRIPTION | ||
| 16 | |||
| 17 | C<IO::Moose> provides a simple mechanism to load several modules in one go. | ||
| 18 | |||
| 19 | C<IO::Moose::*> classes provide an interface mostly compatible with L<IO>. | ||
| 20 | The differences: | ||
| 21 | |||
| 22 | =over | ||
| 23 | |||
| 24 | =item * | ||
| 25 | |||
| 26 | It is based on L<Moose> object framework. | ||
| 27 | |||
| 28 | =item * | ||
| 29 | |||
| 30 | It uses L<Exception::Base> for signaling errors. Most of methods are throwing | ||
| 31 | exception on failure. | ||
| 32 | |||
| 33 | =item * | ||
| 34 | |||
| 35 | The modifiers like C<input_record_separator> are supported on per file handler | ||
| 36 | basis. | ||
| 37 | |||
| 38 | =item * | ||
| 39 | |||
| 40 | It also implements additional methods like C<say>, C<slurp>. | ||
| 41 | |||
| 42 | =back | ||
| 43 | |||
| 44 | =for readme stop | ||
| 45 | |||
| 46 | =cut | ||
| 47 | |||
| 48 | use 5.006; | ||
| 49 | |||
| 50 | use strict; | ||
| 51 | use warnings; | ||
| 52 | |||
| 53 | our $VERSION = '0.1004'; | ||
| 54 | |||
| 55 | use Class::MOP; | ||
| 56 | |||
| 57 | |||
| 58 | use Exception::Base ( | ||
| 59 | '+ignore_package' => [ __PACKAGE__ ], | ||
| 60 | ); | ||
| 61 | |||
| 62 | |||
| 63 | ## no critic qw(RequireArgUnpacking) | ||
| 64 | |||
| 65 | =head1 IMPORTS | ||
| 66 | |||
| 67 | =over | ||
| 68 | |||
| 69 | =item use IO::Moose [I<modules>] | ||
| 70 | |||
| 71 | Loads a modules from C<IO::Moose::*> hierarchy. I.e. C<Handle> parameter | ||
| 72 | loads C<IO::Moose::Handle> module. | ||
| 73 | |||
| 74 | use IO::Moose 'Handle', 'File'; # loads IO::Moose::Handle and ::File. | ||
| 75 | |||
| 76 | If I<modules> list is empty, it loads following modules at default: | ||
| 77 | |||
| 78 | =over | ||
| 79 | |||
| 80 | =item * L<IO::Moose::Handle> | ||
| 81 | |||
| 82 | =item * L<IO::Moose::File> | ||
| 83 | |||
| 84 | =back | ||
| 85 | |||
| 86 | =cut | ||
| 87 | |||
| 88 | sub import { | ||
| 89 | shift; | ||
| 90 | |||
| 91 | my @modules = @_ ? @_ : qw{ Handle File }; | ||
| 92 | |||
| 93 | Class::MOP::load_class($_) foreach ( map { 'IO::Moose::' . $_ } @modules ); | ||
| 94 | |||
| 95 | return 1; | ||
| 96 | }; | ||
| 97 | |||
| 98 | |||
| 99 | 1; | ||
| 100 | |||
| 101 | |||
| 102 | =back | ||
| 103 | |||
| 104 | =begin umlwiki | ||
| 105 | |||
| 106 | = Component Diagram = | ||
| 107 | |||
| 108 | [ <<library>> {=} | ||
| 109 | IO::Moose | ||
| 110 | --------------------------------------- | ||
| 111 | IO::Moose | ||
| 112 | IO::Moose::Handle | ||
| 113 | IO::Moose::Seekable | ||
| 114 | IO::Moose::File | ||
| 115 | MooseX::Types::OpenModeStr | ||
| 116 | MooseX::Types::CanonOpenModeStr | ||
| 117 | MooseX::Types::OpenModeWithLayerStr | ||
| 118 | MooseX::Types::PerlIOLayerStr | ||
| 119 | <<type>> OpenModeStr | ||
| 120 | <<type>> CanonOpenModeStr | ||
| 121 | <<type>> OpenModeWithLayerStr | ||
| 122 | <<type>> PerlIOLayerStr | ||
| 123 | ] | ||
| 124 | |||
| 125 | [<<type>> OpenModeStr] ---|> [<<type>> Str] | ||
| 126 | |||
| 127 | [<<type>> CanonOpenModeStr] ---|> [<<type>> ModeStr] | ||
| 128 | |||
| 129 | [<<type>> OpenModeWithLayerStr] ---|> [<<type>> Str] | ||
| 130 | |||
| 131 | [<<type>> PerlIOLayerStr] ---|> [<<type>> Str] | ||
| 132 | |||
| 133 | = Class Diagram = | ||
| 134 | |||
| 135 | [ <<utility>> | ||
| 136 | IO::Moose | ||
| 137 | ------------ | ||
| 138 | ------------ ] | ||
| 139 | |||
| 140 | [IO::Moose] ---> <<use>> [Class::MOP] | ||
| 141 | |||
| 142 | =end umlwiki | ||
| 143 | |||
| 144 | =head1 SEE ALSO | ||
| 145 | |||
| 146 | L<IO>, L<Moose>. | ||
| 147 | |||
| 148 | =head1 BUGS | ||
| 149 | |||
| 150 | The API is not stable yet and can be changed in future. | ||
| 151 | |||
| 152 | =for readme continue | ||
| 153 | |||
| 154 | =head1 AUTHOR | ||
| 155 | |||
| 156 | Piotr Roszatycki <dexter@cpan.org> | ||
| 157 | |||
| 158 | =head1 LICENSE | ||
| 159 | |||
| 160 | Copyright 2008, 2009 by Piotr Roszatycki <dexter@cpan.org>. | ||
| 161 | |||
| 162 | This program is free software; you can redistribute it and/or modify it | ||
| 163 | under the same terms as Perl itself. | ||
| 164 | |||
| 165 | See L<http://www.perl.com/perl/misc/Artistic.html> |