Class-Tiny
view release on metacpan or search on metacpan
lib/Class/Tiny.pm view on Meta::CPAN
# timestamp => $coderef
# }
The C<import> method uses two class methods, C<prepare_class> and
C<create_attributes> to set up the C<@ISA> array and attributes. Anyone
attempting to extend Class::Tiny itself should use these instead of mocking up
a call to C<import>.
When the first object is created, linearized C<@ISA>, the valid attribute list
and various subroutine references are cached for speed. Ensure that all
inheritance and methods are in place before creating objects. (You don't want
to be changing that once you create objects anyway, right?)
=for Pod::Coverage new get_all_attributes_for get_all_attribute_defaults_for
prepare_class create_attributes
=head1 RATIONALE
=head2 Why this instead of Object::Tiny or Class::Accessor or something else?
I wanted something so simple that it could potentially be used by core Perl
modules I help maintain (or hope to write), most of which either use
L<Class::Struct> or roll-their-own OO framework each time.
L<Object::Tiny> and L<Object::Tiny::RW> were close to what I wanted, but
lacking some features I deemed necessary, and their maintainers have an even
more strict philosophy against feature creep than I have.
I also considered L<Class::Accessor>, which has been around a long time and is
heavily used, but it, too, lacked features I wanted and did things in ways I
considered poor design.
I looked for something else on CPAN, but after checking a dozen class creators
I realized I could implement exactly what I wanted faster than I could search
CPAN for something merely sufficient.
In general, compared to most things on CPAN (other than Object::Tiny),
Class::Tiny is smaller in implementation and simpler in API.
Specifically, here is how Class::Tiny ("C::T") compares to Object::Tiny
("O::T") and Class::Accessor ("C::A"):
FEATURE C::T O::T C::A
--------------------------------------------------------------
attributes defined via import yes yes no
read/write accessors yes no yes
lazy attribute defaults yes no no
provides new yes yes yes
provides DESTROY yes no no
new takes either hashref or list yes no (list) no (hash)
Moo(se)-like BUILD/DEMOLISH yes no no
Moo(se)-like BUILDARGS yes no no
no extraneous methods via @ISA yes yes no
=head2 Why this instead of Moose or Moo?
L<Moose> and L<Moo> are both excellent OO frameworks. Moose offers a powerful
meta-object protocol (MOP), but is slow to start up and has about 30 non-core
dependencies including XS modules. Moo is faster to start up and has about 10
pure Perl dependencies but provides no true MOP, relying instead on its ability
to transparently upgrade Moo to Moose when Moose's full feature set is
required.
By contrast, Class::Tiny has no MOP and has B<zero> non-core dependencies for
Perls in the L<support window|perlpolicy>. It has far less code, less
complexity and no learning curve. If you don't need or can't afford what Moo or
Moose offer, this is intended to be a reasonable fallback.
That said, Class::Tiny offers Moose-like conventions for things like C<BUILD>
and C<DEMOLISH> for some minimal interoperability and an easier upgrade path.
=head1 AUTHOR
David Golden <dagolden@cpan.org>
=head1 CONTRIBUTORS
=for stopwords Dagfinn Ilmari Mannsåker David Golden Gelu Lupas Karen Etheridge Matt S Trout Olivier Mengué Toby Inkster
=over 4
=item *
Dagfinn Ilmari Mannsåker <ilmari@ilmari.org>
=item *
David Golden <xdg@xdg.me>
=item *
Gelu Lupas <gelu@devnull.ro>
=item *
Karen Etheridge <ether@cpan.org>
=item *
Matt S Trout <mstrout@cpan.org>
=item *
Olivier Mengué <dolmen@cpan.org>
=item *
Toby Inkster <tobyink@cpan.org>
=back
=head1 COPYRIGHT AND LICENSE
This software is Copyright (c) 2013 by David Golden.
This is free software, licensed under:
The Apache License, Version 2.0, January 2004
=cut
( run in 2.137 seconds using v1.01-cache-2.11-cpan-39bf76dae61 )