1MouseX::NativeTraits::CUosuenrteCro(n3t)ributed Perl DocMuomuesnetXa:t:iNoantiveTraits::Counter(3)
2
3
4
6 MouseX::NativeTraits::Counter - Helper trait for counter attributes
7
9 package MyHomePage;
10 use Mouse;
11
12 has 'counter' => (
13 traits => ['Counter'],
14 is => 'ro',
15 isa => 'Num',
16 default => 0,
17 handles => {
18 inc_counter => 'inc',
19 dec_counter => 'dec',
20 reset_counter => 'reset',
21 },
22 );
23
24 my $page = MyHomePage->new();
25 $page->inc_counter; # same as $page->counter( $page->counter + 1 );
26 $page->dec_counter; # same as $page->counter( $page->counter - 1 );
27
29 This module provides a simple counter attribute, which can be
30 incremented and decremented.
31
32 If your attribute definition does not include any of is, isa, default
33 or handles but does use the "Counter" trait, then this module applies
34 defaults as in the "SYNOPSIS" above. This allows for a very basic
35 counter definition:
36
37 has 'foo' => (traits => ['Counter']);
38 $obj->inc_foo;
39
41 These methods are implemented in
42 MouseX::NativeTraits::MethodProvider::Counter. It is important to note
43 that all those methods do in place modification of the value stored in
44 the attribute.
45
46 set($value)
47 Set the counter to the specified value.
48
49 inc Increments the value stored in this slot by 1. Providing an
50 argument will cause the counter to be increased by specified
51 amount.
52
53 dec Decrements the value stored in this slot by 1. Providing an
54 argument will cause the counter to be increased by specified
55 amount.
56
57 reset
58 Resets the value stored in this slot to it's default value.
59
61 meta
62 method_provider_class
63 helper_type
64
66 MouseX::NativeTraits
67
68
69
70perl v5.36.0 2023-01-20 MouseX::NativeTraits::Counter(3)