1Moose::Meta::Attribute:U:sNeartiCvoenM:to:roTisrbeau:it:teM:de:tCPaoe:ur:nlAtteDtror(ci3ub)muetnet:a:tNiaotnive::Trait::Counter(3)
2
3
4
6 Moose::Meta::Attribute::Native::Trait::Counter - Helper trait for Int
7 attributes which represent counters
8
10 version 2.2013
11
13 package MyHomePage;
14 use Moose;
15
16 has 'counter' => (
17 traits => ['Counter'],
18 is => 'ro',
19 isa => 'Num',
20 default => 0,
21 handles => {
22 inc_counter => 'inc',
23 dec_counter => 'dec',
24 reset_counter => 'reset',
25 },
26 );
27
28 my $page = MyHomePage->new();
29 $page->inc_counter; # same as $page->counter( $page->counter + 1 );
30 $page->dec_counter; # same as $page->counter( $page->counter - 1 );
31
32 my $count_by_twos = 2;
33 $page->inc_counter($count_by_twos);
34
36 This trait provides native delegation methods for counters. A counter
37 can be any sort of number (integer or not). The delegation methods
38 allow you to increment, decrement, or reset the value.
39
41 If you don't provide an "isa" value for your attribute, it will default
42 to "Num".
43
45 · set($value)
46
47 Sets the counter to the specified value and returns the new value.
48
49 This method requires a single argument.
50
51 · inc
52
53 · inc($arg)
54
55 Increases the attribute value by the amount of the argument, or by
56 1 if no argument is given. This method returns the new value.
57
58 This method accepts a single argument.
59
60 · dec
61
62 · dec($arg)
63
64 Decreases the attribute value by the amount of the argument, or by
65 1 if no argument is given. This method returns the new value.
66
67 This method accepts a single argument.
68
69 · reset
70
71 Resets the value stored in this slot to its default value, and
72 returns the new value.
73
75 See "BUGS" in Moose for details on reporting bugs.
76
78 · Stevan Little <stevan.little@iinteractive.com>
79
80 · Dave Rolsky <autarch@urth.org>
81
82 · Jesse Luehrs <doy@tozt.net>
83
84 · Shawn M Moore <code@sartak.org>
85
86 · יובל קוג'מן (Yuval Kogman) <nothingmuch@woobling.org>
87
88 · Karen Etheridge <ether@cpan.org>
89
90 · Florian Ragwitz <rafl@debian.org>
91
92 · Hans Dieter Pearcey <hdp@weftsoar.net>
93
94 · Chris Prather <chris@prather.org>
95
96 · Matt S Trout <mst@shadowcat.co.uk>
97
99 This software is copyright (c) 2006 by Infinity Interactive, Inc.
100
101 This is free software; you can redistribute it and/or modify it under
102 the same terms as the Perl 5 programming language system itself.
103
104
105
106perl v5.32.0 Moose2:0:2M0e-t0a7:-:2A8ttribute::Native::Trait::Counter(3)