1MooseX::SetOnce(3)    User Contributed Perl Documentation   MooseX::SetOnce(3)
2
3
4

NAME

6       MooseX::SetOnce - write-once, read-many attributes for Moose
7

VERSION

9       version 0.203
10

SYNOPSIS

12       Add the "SetOnce" trait to attributes:
13
14         package Class;
15         use Moose;
16         use MooseX::SetOnce;
17
18         has some_attr => (
19           is     => 'rw',
20           traits => [ qw(SetOnce) ],
21         );
22
23       ...and then you can only set them once:
24
25         my $object = Class->new;
26
27         $object->some_attr(10);  # works fine
28         $object->some_attr(20);  # throws an exception: it's already set!
29

DESCRIPTION

31       The 'SetOnce' attribute lets your class have attributes that are not
32       lazy and not set, but that cannot be altered once set.
33
34       The logic is very simple:  if you try to alter the value of an
35       attribute with the SetOnce trait, either by accessor or writer, and the
36       attribute has a value, it will throw an exception.
37
38       If the attribute has a clearer, you may clear the attribute and set it
39       again.
40

PERL VERSION

42       This library should run on perls released even a long time ago.  It
43       should work on any version of perl released in the last five years.
44
45       Although it may work on older versions of perl, no guarantee is made
46       that the minimum required version will not be increased.  The version
47       may be increased for any reason, and there is no promise that patches
48       will be accepted to lower the minimum required perl.
49

AUTHOR

51       Ricardo SIGNES <cpan@semiotic.systems>
52

CONTRIBUTORS

54       •   Jesse Luehrs <doy@tozt.net>
55
56       •   Karen Etheridge <ether@cpan.org>
57
58       •   Kent Fredric <kentfredric@gmail.com>
59
60       •   Ricardo Signes <rjbs@semiotic.systems>
61
63       This software is copyright (c) 2022 by Ricardo SIGNES.
64
65       This is free software; you can redistribute it and/or modify it under
66       the same terms as the Perl 5 programming language system itself.
67
68
69
70perl v5.36.0                      2023-01-20                MooseX::SetOnce(3)
Impressum