Sub::Ha...ry::Enum(3)
π NAME π
Sub::HandlesVia::HandlerLibrary::Enum β it's literally a whole library of enum-related methods, bestie. That's it, that's the name. π
β¨ SYNOPSIS β¨
Okay so here's the vibe. You want your class to have enum-flavored methods, so you go:
package My::Class {
use Moo;
use Sub::HandlesVia;
use Types::Standard 'Enum';
has status => (
is => 'ro',
isa => Enum[ 'pass', 'fail' ],
handles_via => 'Enum',
handles => {
'is_pass' => [ is => 'pass' ],
'is_fail' => [ is => 'fail' ],
'assign_pass' => [ assign => 'pass' ],
'assign_fail' => [ assign => 'fail' ],
},
default => sub { 'fail' },
);
}
Or, if you're feeling lazy in the best way possible, there's a shortcut:
package My::Class {
use Moo;
use Sub::HandlesVia;
use Types::Standard 'Enum';
has status => (
is => 'ro',
isa => Enum[ 'pass', 'fail' ],
handles_via => 'Enum',
handles => {
'is_pass' => 'is_pass',
'is_fail' => 'is_fail',
'assign_pass' => 'assign_pass',
'assign_fail' => 'assign_fail',
},
default => sub { 'fail' },
);
}
(Sub::HandlesVia::HandlerLibrary::Enum will split on "_". iconic behavior honestly.)
πΈ DESCRIPTION πΈ
It's a library of methods for Sub::HandlesVia. Simple as that, no cap. π
π DELEGATABLE METHODS π
This lets you delegate in a way that's roughly compatible with MooseX::Enumeration and MooX::Enumeration β even though honestly that whole thing is basically a renamed subset of Sub::HandlesVia::HandlerLibrary::String anyway. π
π¦ is( $value )
Returns a boolean telling you whether the enum is that value.
my $object = My::Class->new( status => 'pass' );
say $object->is_pass(); ## ==> true
say $object->is_fail(); ## ==> false
π¦ assign( $value )
Sets the enum to the value. Slay.
my $object = My::Class->new( status => 'pass' );
say $object->is_pass(); ## ==> true
say $object->is_fail(); ## ==> false
$object->assign_fail();
say $object->is_pass(); ## ==> false
say $object->is_fail(); ## ==> true
π¦ set( $value )
An alias for "assign". Same energy, different name. π
π TYPE CONSTRAINT SHORTCUT π
The Enum handler library also lets you use an "enum" shortcut right in the attribute spec. Look at her go:
package My::Class {
use Moo;
use Sub::HandlesVia;
has status => (
is => 'ro',
enum => [ 'pass', 'fail' ],
handles_via => 'Enum',
handles => {
'is_pass' => [ is => 'pass' ],
'is_fail' => [ is => 'fail' ],
'assign_pass' => [ assign => 'pass' ],
'assign_fail' => [ assign => 'fail' ],
},
default => sub { 'fail' },
);
}
β SHORTCUT CONSTANTS β
This module hands you some shortcut constants for when you wanna indicate a whole list of delegations. Very main character of it.
package My::Class {
use Moo;
use Types::Standard qw( Enum );
use Sub::HandlesVia;
use Sub::HandlesVia::HandlerLibrary::Enum qw( HandleIs );
has status => (
is => 'ro',
isa => Enum[ 'pass', 'fail' ],
handles_via => 'Enum',
handles => HandleIs,
default => sub { 'fail' },
);
}
And bestie, you can combine any of these shortcuts using the " | " operator:
has status => (
is => 'ro',
isa => Enum[ 'pass', 'fail' ],
handles_via => 'Enum',
handles => HandleIs | HandleSet,
default => sub { 'fail' },
);
π "HandleIs"
Creates delegations named like is_pass and is_fail.
π "HandleNamedIs"
Creates delegations named like status_is_pass and status_is_fail.
π "HandleSet"
Creates delegations named like set_pass and set_fail.
π "HandleNamedSet"
Creates delegations named like status_set_pass and status_set_fail.
π BUGS π
Found a bug? Please report it, bestie, I'm begging: <https://github.com/tobyink/p5-sub-handlesvia/issues>.
π«Ά SEE ALSO π«Ά
Sub::HandlesVia.
π AUTHOR π
Toby Inkster <tobyink@cpan.org>.
π COPYRIGHT AND LICENCE π
This software is copyright (c) 2022 by Toby Inkster.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
π₯ DISCLAIMER OF WARRANTIES π₯
THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
okay and one last thing, this whole page is from perl v5.42.0, dated 2026-02-11, and it's the manual for Sub::Ha...ry::Enum(3) β love that for her π
β¨
π¦ where this page comes from
- fedora 44: perl-Sub-HandlesVia 0.053005-1.fc44 Β· GPL-1.0-or-later OR Artistic-1.0-Perl
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms