1Sub::HandlesVia::HandleUrsLeirbrCaornyt:r:iEbnuutme(d3S)Puebr:l:HDaoncdulmeesnVtiaat:i:oHnandlerLibrary::Enum(3)
2
3
4

NAME

6       Sub::HandlesVia::HandlerLibrary::Enum - library of enum-related methods
7

SYNOPSIS

9         package My::Class {
10           use Moo;
11           use Sub::HandlesVia;
12           use Types::Standard 'Enum';
13           has status => (
14             is => 'ro',
15             isa => Enum[ 'pass', 'fail' ],
16             handles_via => 'Enum',
17             handles => {
18               'is_pass'      => [ is     => 'pass' ],
19               'is_fail'      => [ is     => 'fail' ],
20               'assign_pass'  => [ assign => 'pass' ],
21               'assign_fail'  => [ assign => 'fail' ],
22             },
23             default => sub { 'fail' },
24           );
25         }
26
27       Or, using a shortcut:
28
29         package My::Class {
30           use Moo;
31           use Sub::HandlesVia;
32           use Types::Standard 'Enum';
33           has status => (
34             is => 'ro',
35             isa => Enum[ 'pass', 'fail' ],
36             handles_via => 'Enum',
37             handles => {
38               'is_pass'      => 'is_pass',
39               'is_fail'      => 'is_fail',
40               'assign_pass'  => 'assign_pass',
41               'assign_fail'  => 'assign_fail',
42             },
43             default => sub { 'fail' },
44           );
45         }
46
47       (Sub::HandlesVia::HandlerLibrary::Enum will split on "_".)
48

DESCRIPTION

50       This is a library of methods for Sub::HandlesVia.
51

DELEGATABLE METHODS

53       This allows for delegation roughly compatible with MooseX::Enumeration
54       and MooX::Enumeration, even though that's basically a renamed subset of
55       Sub::HandlesVia::HandlerLibrary::String anyway.
56
57   is( $value )
58       Returns a boolean indicating whether the enum is that value.
59
60         my $object = My::Class->new( status => 'pass' );
61         say $object->is_pass(); ## ==> true
62         say $object->is_fail(); ## ==> false
63
64   assign( $value )
65       Sets the enum to the value.
66
67         my $object = My::Class->new( status => 'pass' );
68         say $object->is_pass(); ## ==> true
69         say $object->is_fail(); ## ==> false
70         $object->assign_fail();
71         say $object->is_pass(); ## ==> false
72         say $object->is_fail(); ## ==> true
73
74   set( $value )
75       An alias for "assign".
76

TYPE CONSTRAINT SHORTCUT

78       The Enum handler library also allows an "enum" shortcut in the
79       attribute spec.
80
81         package My::Class {
82           use Moo;
83           use Sub::HandlesVia;
84           has status => (
85             is          => 'ro',
86             enum        => [ 'pass', 'fail' ],
87             handles_via => 'Enum',
88             handles     => {
89               'is_pass'      => [ is     => 'pass' ],
90               'is_fail'      => [ is     => 'fail' ],
91               'assign_pass'  => [ assign => 'pass' ],
92               'assign_fail'  => [ assign => 'fail' ],
93             },
94             default     => sub { 'fail' },
95           );
96         }
97

SHORTCUT CONSTANTS

99       This module provides some shortcut constants for indicating a list of
100       delegations.
101
102         package My::Class {
103           use Moo;
104           use Types::Standard qw( Enum );
105           use Sub::HandlesVia;
106           use Sub::HandlesVia::HandlerLibrary::Enum qw( HandleIs );
107           has status => (
108             is          => 'ro',
109             isa         => Enum[ 'pass', 'fail' ],
110             handles_via => 'Enum',
111             handles     => HandleIs,
112             default     => sub { 'fail' },
113           );
114         }
115
116       Any of these shortcuts can be combined using the " | " operator.
117
118           has status => (
119             is          => 'ro',
120             isa         => Enum[ 'pass', 'fail' ],
121             handles_via => 'Enum',
122             handles     => HandleIs | HandleSet,
123             default     => sub { 'fail' },
124           );
125
126   "HandleIs"
127       Creates delegations named like "is_pass" and "is_fail".
128
129   "HandleNamedIs"
130       Creates delegations named like "status_is_pass" and "status_is_fail".
131
132   "HandleSet"
133       Creates delegations named like "set_pass" and "set_fail".
134
135   "HandleNamedSet"
136       Creates delegations named like "status_set_pass" and "status_set_fail".
137

BUGS

139       Please report any bugs to
140       <https://github.com/tobyink/p5-sub-handlesvia/issues>.
141

SEE ALSO

143       Sub::HandlesVia.
144

AUTHOR

146       Toby Inkster <tobyink@cpan.org>.
147
149       This software is copyright (c) 2022 by Toby Inkster.
150
151       This is free software; you can redistribute it and/or modify it under
152       the same terms as the Perl 5 programming language system itself.
153

DISCLAIMER OF WARRANTIES

155       THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED
156       WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
157       MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
158
159
160
161perl v5.38.0                      2023-S0u7b-:2:1HandlesVia::HandlerLibrary::Enum(3)
Impressum