Class-Tiny

 view release on metacpan or  search on metacpan

README  view on Meta::CPAN

    default will be "undef".

        my $def = Class::Tiny->get_all_attribute_defaults_for("Employee");
        # returns {
        #   name => undef,
        #   ssn => undef
        #   timestamp => $coderef
        # }

    The "import" method uses two class methods, "prepare_class" and
    "create_attributes" to set up the @ISA array and attributes. Anyone
    attempting to extend Class::Tiny itself should use these instead of
    mocking up a call to "import".

    When the first object is created, linearized @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?)

RATIONALE
  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 Class::Struct or roll-their-own OO framework each time.

    Object::Tiny and 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 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

  Why this instead of Moose or Moo?
    Moose and 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 zero non-core dependencies
    for Perls in the support window. 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
    "BUILD" and "DEMOLISH" for some minimal interoperability and an easier
    upgrade path.

AUTHOR
    David Golden <dagolden@cpan.org>

CONTRIBUTORS
    *   Dagfinn Ilmari Mannsåker <ilmari@ilmari.org>

    *   David Golden <xdg@xdg.me>

    *   Gelu Lupas <gelu@devnull.ro>

    *   Karen Etheridge <ether@cpan.org>

    *   Matt S Trout <mstrout@cpan.org>

    *   Olivier Mengué <dolmen@cpan.org>

    *   Toby Inkster <tobyink@cpan.org>

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



( run in 2.001 seconds using v1.01-cache-2.11-cpan-39bf76dae61 )