File Coverage

blib/lib/Moose/Tiny.pm
Criterion Covered Total %
statement 4 6 66.6
branch n/a
condition n/a
subroutine 2 2 100.0
pod n/a
total 6 8 75.0


line stmt bran cond sub pod time code
1             package Moose::Tiny;
2 3     3   34841 use strict;
  3         6  
  3         182  
3             our $VERSION = '0.04';
4 3     3   1490 use Moose();
  0            
  0            
5              
6             use Moose::Exporter;
7              
8             my ( $isub, $usub ) = Moose::Exporter->build_import_methods( also => 'Moose' );
9              
10             {
11             no strict 'refs';
12             *{ __PACKAGE__ . '::unimport' } = $usub;
13             }
14              
15              
16             sub import {
17             my $CALLER = caller();
18             my $pkg = shift;
19             my $meta = Moose::Meta::Class->initialize($CALLER);
20             for my $name (@_) {
21             die q[Invalid accessor name 'undef'] unless defined $name;
22             die qq[Invalid accessor name '$name'] if ref $name;
23             die qq[Invalid accessor name '$name'] unless $name =~ /^[^\W\d]\w*$/s;
24             $meta->add_attribute( $name => { is => 'ro' } );
25             }
26             @_ = ( $pkg, grep { /^-/ } @_ );
27             goto $isub;
28             }
29              
30             no Moose; # unimport moose features
31             1; # Magic true value required at end of module
32             __END__
33              
34             =head1 NAME
35              
36             Moose::Tiny - Why Should Object::Tiny get all the Fun
37              
38              
39             =head1 VERSION
40              
41             This document describes Moose::Tiny version 0.0.3
42              
43              
44             =head1 SYNOPSIS
45              
46             # Define a class
47             package Foo;
48              
49             use Moose::Tiny qw{ bar baz };
50              
51             1;
52              
53              
54             # Use the class
55             my $object = Foo->new( bar => 1 );
56              
57             print "bar is " . $object->bar . "\n";
58            
59              
60             =head1 DESCRIPTION
61              
62             I was looking at Object::Tiny and thought, wow I bet I could do that really
63             easily with Moose. I was right.
64              
65             =head1 INTERFACE
66              
67             None. Moose::Tiny currently exports what Moose itself exports. Simply call it
68             with a list of attribute names and it will create read only accessors for you.
69              
70             use Moose::Tiny qw(foo bar);
71            
72             or a larger list
73              
74             use Moose::Tiny qw(
75             item_font_face
76             item_font_color
77             item_font_size
78             item_text_content
79             item_display_time
80             seperator_font_face
81             seperator_font_color
82             seperator_font_size
83             seperator_text_content
84             )
85              
86             This will create a bunch of simple accessors, and set the inheritance to be
87             the child of Moose::Object, just like if you'd created them with Moose itself.
88             It will also make your class immutable for performance reasons (and because if
89             you're using this you probably don't care).
90              
91             =head1 WHY?
92              
93             Well I was looking at Object::Tiny's docs and realized that Moose wasn't even
94             in the argument. I felt bad. So I decided hey I could make this work.
95              
96             Object::Tiny has a bunch of statistics to show why it is better than
97             Class::Accessor::Fast. Here are some statistics of our own.
98              
99             =over
100              
101             =item Moose::Tiny is 8% shorter to type than Object::Tiny
102              
103             That's right, Moose is one less letter than Object, and since otherwise the
104             APIs are identical that's an 8% savings overall.
105              
106             =item Moose::Tiny brings you the full power of Moose
107              
108             If you buy now you get C<with>, C<around>, C<after>, C<before> and several
109             other goodies as well! Call now operators are standing by.
110              
111             =back
112              
113             Really that's all I got. Since you get all the Moose metaobject goodness our
114             memory footprint is probably a fair bit larger ... but hey 8% savings when
115             you're typing the code out!
116              
117             =head1 CAVEATS
118              
119             Moose works differently from Object::Tiny. Most importantly moose won't
120             auto-vivify attribute slots, so if you don't define it in the command line it
121             won't exist in the instance data structure, even if you pass a value to new();
122             Object::Tiny doesn't document this behavior but it is tested.
123              
124             Also attribute slots in Moose are always created even if they're undefined.
125             This behavior *may* change in the future, it's undocumented in Moose, but
126             Object::Tiny expect that if you haven't populated an attribute, that attribute
127             doesn't exist in the instance data structure. This is also not really
128             documented, but is tested for.
129              
130             Alias has reported some more caveats:
131              
132             =head2 Installation
133              
134             Moose::Tiny has a number of recursive dependencies (and a few more
135             build_requires deps not shown) with non-perfect cpan testers results (72%
136             aggregate success installing).
137              
138             Moose::Tiny has all of the build requirements of Moose itself. Be prepared to
139             install everything listed in
140             http://cpandeps.cantrell.org.uk/?module=Moose%3A%3ATiny
141              
142             =head2 Memory
143              
144             Moose::Tiny uses 4.5 megabytes of memory. This is around 550 times larger
145             than Object::Tiny, or a more impressive sounding 55,000% larger :)
146              
147             =head2 Startup
148              
149             Moose::Tiny takes around a second to load up on the virtual I'm currently
150             working in. Granted that's also in the debugger, so it's WAY slower than
151             it could be, but Object::Tiny does not take any noticable time to load,
152             even in the same scenario.
153              
154             This is also an overhead cost from Moose. Neither have been reccomended for
155             use in a critical situation where you are constantly restarting the perl
156             process (eg. CGI). If you find yourself in this situation either try to use a
157             persistant environment (pperl, mod_perl, fastcgi) or try Object::Tiny. On the
158             plus side, our API is 100% compatible so you can switch bak and forth easily.
159              
160             =head2 Benchmarks
161              
162             Benchmarking constructor plus accessors...
163             Rate moose tiny
164             moose 94607/s -- -56%
165             tiny 213675/s 126% --
166              
167             Benchmarking constructor alone...
168             Rate moose tiny
169             moose 136799/s -- -68%
170             tiny 421941/s 208% --
171              
172             Benchmarking accessors alone...
173             Rate moose tiny
174             moose 485/s -- -19%
175             tiny 599/s 23% --
176              
177             =head1 DEPENDENCIES
178              
179             Moose obviously.
180              
181             =head1 INCOMPATIBILITIES
182              
183             Some people's sense of humor.
184              
185             =head1 BUGS AND LIMITATIONS
186              
187             Please report any bugs or feature requests to
188             C<bug-moose-tiny@rt.cpan.org>, or through the web interface at
189             L<http://rt.cpan.org>.
190              
191             =head1 AUTHOR
192              
193             Chris Prather C<< <perigrin@cpan.org> >>
194              
195             =head1 LICENCE AND COPYRIGHT
196              
197             Copyright (c) 2007 - 2009 Chris Prather C<< <chris@prather.org> >>. Some
198             rights reserved.
199              
200             This module is free software; you can redistribute it and/or
201             modify it under the same terms as Perl itself. See L<perlartistic>.
202              
203              
204             =head1 DISCLAIMER OF WARRANTY
205              
206             BECAUSE THIS SOFTWARE IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
207             FOR THE SOFTWARE, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
208             OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
209             PROVIDE THE SOFTWARE "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER
210             EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
211             WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE
212             ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE SOFTWARE IS WITH
213             YOU. SHOULD THE SOFTWARE PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL
214             NECESSARY SERVICING, REPAIR, OR CORRECTION.
215              
216             IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
217             WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
218             REDISTRIBUTE THE SOFTWARE AS PERMITTED BY THE ABOVE LICENCE, BE
219             LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL,
220             OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE
221             THE SOFTWARE (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING
222             RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A
223             FAILURE OF THE SOFTWARE TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF
224             SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
225             SUCH DAMAGES.