| 1 |
NAME |
| 2 |
Class::Tiny::Antlers - Moose-like sugar for Class::Tiny |
| 3 |
|
| 4 |
SYNOPSIS |
| 5 |
{ |
| 6 |
package Point; |
| 7 |
use Class::Tiny::Antlers; |
| 8 |
has x => (is => 'ro'); |
| 9 |
has y => (is => 'ro'); |
| 10 |
} |
| 11 |
|
| 12 |
{ |
| 13 |
package Point3D; |
| 14 |
use Class::Tiny::Antlers; |
| 15 |
extends 'Point'; |
| 16 |
has z => (is => 'ro'); |
| 17 |
} |
| 18 |
|
| 19 |
DESCRIPTION |
| 20 |
Class::Tiny::Antlers provides Moose-like `has`, `extends`, `with`, |
| 21 |
`before`, `after` and `around` keywords for Class::Tiny. (The `with` |
| 22 |
keyword requires Role::Tiny; method modifiers require |
| 23 |
Class::Method::Modifiers.) |
| 24 |
|
| 25 |
Class::Tiny doesn't support all Moose's attribute options; `has` should |
| 26 |
throw you an error if you try to do something it doesn't support (like |
| 27 |
triggers). |
| 28 |
|
| 29 |
Class::Tiny::Antlers does however hack in support for `is => 'ro'` and |
| 30 |
Moo-style `is => 'rwp'`, clearers and predicates. |
| 31 |
|
| 32 |
From version 0.24, Class::Tiny::Antlers also adds support for `isa` and |
| 33 |
`coerce` using Type::Tiny. (I mean, this is a TOBYINK module, so what do |
| 34 |
you expect?!) Technically MooseX::Types, MouseX::Types, Specio, and |
| 35 |
Type::Nano should work, but these are less tested. |
| 36 |
|
| 37 |
Export |
| 38 |
By default, Class::Tiny::Antlers exports `has`, `with` and `extends`, and |
| 39 |
also imports strict into its caller. You can optionally also import |
| 40 |
`confess` and warnings: |
| 41 |
|
| 42 |
use Class::Tiny::Antlers qw( -default confess warnings ); |
| 43 |
|
| 44 |
And Class::Method::Modifiers keywords: |
| 45 |
|
| 46 |
use Class::Tiny::Antlers qw( -default before after around ); |
| 47 |
use Class::Tiny::Antlers qw( -default -cmm ); # same thing |
| 48 |
|
| 49 |
If you just want everything: |
| 50 |
|
| 51 |
use Class::Tiny::Antlers qw( -all ); |
| 52 |
|
| 53 |
Class::Tiny::Antlers also ensures that Class::Tiny's import method is |
| 54 |
called for your class. |
| 55 |
|
| 56 |
You can put a `no Class::Tiny::Antlers` statement at the end of your class |
| 57 |
definition to wipe the imported functions out of your namespace. (This |
| 58 |
does not unimport strict/warnings though.) To clean up your namespace more |
| 59 |
thoroughly, use something like namespace::sweep. |
| 60 |
|
| 61 |
Functions |
| 62 |
`has $attr, %spec` |
| 63 |
Create an attribute. The specification hash roughly supports `is`, |
| 64 |
`default`, `clearer` and `predicate` as per Moose and Moo. |
| 65 |
|
| 66 |
`extends @classes` |
| 67 |
Set the base class(es) for your class. |
| 68 |
|
| 69 |
`with @roles` |
| 70 |
Compose Role::Tiny roles with your class. |
| 71 |
|
| 72 |
`before $name, \&code` |
| 73 |
Install a `before` modifier using Class::Method::Modifiers. |
| 74 |
|
| 75 |
`after $name, \&code` |
| 76 |
Install a `after` modifier using Class::Method::Modifiers. |
| 77 |
|
| 78 |
`around $name, \&code` |
| 79 |
Install a `around` modifier using Class::Method::Modifiers. |
| 80 |
|
| 81 |
`confess $format, @list` |
| 82 |
`sprintf`-fueled version of Carp's `confess`. |
| 83 |
|
| 84 |
Methods |
| 85 |
Class::Tiny::Antlers inherits the `get_all_attributes_for` and |
| 86 |
`get_all_attribute_defaults_for` methods from Class::Tiny, and also |
| 87 |
provides: |
| 88 |
|
| 89 |
`Class::Tiny::Antlers->get_all_attribute_specs_for($class)` |
| 90 |
Gets Moose-style attribute specification hashes for all the class' |
| 91 |
attributes as a big hashref. (Includes inherited attributes.) |
| 92 |
|
| 93 |
BUGS |
| 94 |
Please report any bugs to |
| 95 |
<http://rt.cpan.org/Dist/Display.html?Queue=Class-Tiny-Antlers>. |
| 96 |
|
| 97 |
SEE ALSO |
| 98 |
Class::Tiny, Role::Tiny, Class::Method::Modifiers, Type::Tiny::Manual. |
| 99 |
|
| 100 |
Moose, Mouse, Moo. |
| 101 |
|
| 102 |
AUTHOR |
| 103 |
Toby Inkster <[email protected]>. |
| 104 |
|
| 105 |
COPYRIGHT AND LICENCE |
| 106 |
This software is copyright (c) 2013, 2019 by Toby Inkster. |
| 107 |
|
| 108 |
This is free software; you can redistribute it and/or modify it under the |
| 109 |
same terms as the Perl 5 programming language system itself. |
| 110 |
|
| 111 |
DISCLAIMER OF WARRANTIES |
| 112 |
THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED |
| 113 |
WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF |
| 114 |
MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
| 115 |
|