1MouseX::NativeTraits(3)User Contributed Perl DocumentatioMnouseX::NativeTraits(3)
2
3
4

NAME

6       MouseX::NativeTraits - Extend your attribute interfaces for Mouse
7

VERSION

9       This document describes MouseX::NativeTraits version 1.09.
10

SYNOPSIS

12           package MyClass;
13           use Mouse;
14
15           has mapping => (
16               traits    => ['Hash'],
17               is        => 'rw',
18               isa       => 'HashRef[Str]',
19               default   => sub { +{} },
20               handles   => {
21                   exists_in_mapping => 'exists',
22                   ids_in_mapping    => 'keys',
23                   get_mapping       => 'get',
24                   set_mapping       => 'set',
25                   set_quantity      => [ set => 'quantity' ],
26               },
27           );
28

DESCRIPTION

30       While Mouse attributes provide a way to name your accessors, readers,
31       writers, clearers and predicates, MouseX::NativeTraits provides
32       commonly used attribute helper methods for more specific types of data.
33
34       As seen in the "SYNOPSIS", you specify the data structure via the
35       "traits" parameter. These traits will be loaded automatically, so you
36       need not load MouseX::NativeTraits explicitly.
37
38       This extension is compatible with Moose native traits, although it is
39       not a part of Mouse core.
40

PARAMETERS

42   handles
43       This is like "handles" in "has" in Mouse, but only HASH references are
44       allowed.  Keys are method names that you want installed locally, and
45       values are methods from the method providers (below).  Currying with
46       delegated methods works normally for "handles".
47

NATIVE TRAITS

49   Array
50       Common methods for array references.
51
52           has 'queue' => (
53              traits     => ['Array'],
54              is         => 'ro',
55              isa        => 'ArrayRef[Str]',
56              default    => sub { [] },
57              handles    => {
58                  add_item  => 'push',
59                  next_item => 'shift',
60              }
61           );
62
63       See MouseX::NativeTraits::ArrayRef.
64
65   Hash
66       Common methods for hash references.
67
68           has 'options' => (
69               traits    => ['Hash'],
70               is        => 'ro',
71               isa       => 'HashRef[Str]',
72               default   => sub { {} },
73               handles   => {
74                   set_option => 'set',
75                   get_option => 'get',
76                   has_option => 'exists',
77               }
78           );
79
80       See MouseX::NativeTraits::HashRef.
81
82   Code
83       Common methods for code references.
84
85           has 'callback' => (
86              traits     => ['Code'],
87              is         => 'ro',
88              isa        => 'CodeRef',
89              default    => sub { sub { 'called' } },
90              handles    => {
91                  call => 'execute',
92              }
93           );
94
95       See MouseX::NativeTraits::CodeRef.
96
97   Bool
98       Common methods for boolean values.
99
100           has 'is_lit' => (
101               traits    => ['Bool'],
102               is        => 'rw',
103               isa       => 'Bool',
104               default   => 0,
105               handles   => {
106                   illuminate  => 'set',
107                   darken      => 'unset',
108                   flip_switch => 'toggle',
109                   is_dark     => 'not',
110               }
111           );
112
113       See MouseX::NativeTraits::Bool.
114
115   String
116       Common methods for string operations.
117
118           has text => (
119               traits    => ['String'],
120               is        => 'rw',
121               isa       => 'Str',
122               default   => q{},
123               handles   => {
124                   add_text     => 'append',
125                   replace_text => 'replace', # or replace_globally
126               }
127           );
128
129       See MouseX::NativeTraits::Str.
130
131   Number
132       Common numerical operations.
133
134           has value => (
135               traits    => ['Number'],
136               is        => 'ro',
137               isa       => 'Int',
138               default   => 5,
139               handles   => {
140                   set => 'set',
141                   add => 'add',
142                   sub => 'sub',
143                   mul => 'mul',
144                   div => 'div',
145                   mod => 'mod',
146                   abs => 'abs',
147               }
148           );
149
150       See MouseX::NativeTraits::Num.
151
152   Counter
153       Methods for incrementing and decrementing a counter attribute.
154
155           has counter => (
156               traits    => ['Counter'],
157               is        => 'ro',
158               isa       => 'Num',
159               default   => 0,
160               handles   => {
161                   inc_counter   => 'inc',
162                   dec_counter   => 'dec',
163                   reset_counter => 'reset',
164               }
165           );
166
167       See MouseX::NativeTraits::Counter.
168

DEPENDENCIES

170       Perl 5.6.2 or later.
171

BUGS

173       All complex software has bugs lurking in it, and this module is no
174       exception. If you find a bug please either email me, or add the bug to
175       cpan-RT.
176

SEE ALSO

178       Mouse
179
180       MouseX::AttributeHelpers
181
182       Moose
183
184       Moose::Meta::Attribute::Native
185
186       MooseX::AttributeHelpers
187

AUTHORS

189       Goro Fuji (gfx) <gfuji(at)cpan.org>
190
191       This module is based on Moose native traits written by Stevan Little
192       and others.
193
195       Copyright (c) 2010, Goro Fuji (gfx), mostly based on Moose, which is
196       (c) Infinity Interactive, Inc (<http://www.iinteractive.com>).
197
198       This library is free software; you can redistribute it and/or modify it
199       under the same terms as Perl itself. See perlartistic for details.
200
201
202
203perl v5.28.1                      2012-11-26           MouseX::NativeTraits(3)
Impressum