1Sub::HandlesVia::HandleUrsLeirbrCaornyt:r:iNbuumtbeSedurb(P:3e:)rHlanDdolceusmVeinat:a:tHiaonndlerLibrary::Number(3)
2
3
4
6 Sub::HandlesVia::HandlerLibrary::Number - library of number-related
7 methods
8
10 package My::Class {
11 use Moo;
12 use Sub::HandlesVia;
13 use Types::Standard 'Num';
14 has attr => (
15 is => 'rwp',
16 isa => Num,
17 handles_via => 'Number',
18 handles => {
19 'my_abs' => 'abs',
20 'my_add' => 'add',
21 'my_cmp' => 'cmp',
22 'my_div' => 'div',
23 'my_eq' => 'eq',
24 'my_ge' => 'ge',
25 'my_get' => 'get',
26 'my_gt' => 'gt',
27 'my_le' => 'le',
28 'my_lt' => 'lt',
29 'my_mod' => 'mod',
30 'my_mul' => 'mul',
31 'my_ne' => 'ne',
32 'my_set' => 'set',
33 'my_sub' => 'sub',
34 },
35 );
36 }
37
39 This is a library of methods for Sub::HandlesVia.
40
42 "abs()"
43 Finds the absolute value of the current number, updating the attribute.
44
45 my $object = My::Class->new( attr => -5 );
46 $object->my_abs;
47 say $object->attr; ## ==> 5
48
49 "add( $addend )"
50 Arguments: Num.
51
52 Adds a number to the existing number, updating the attribute.
53
54 my $object = My::Class->new( attr => 4 );
55 $object->my_add( 5 );
56 say $object->attr; ## ==> 9
57
58 "cmp( $num )"
59 Arguments: Num.
60
61 Returns "$object->attr <=> $num".
62
63 "div( $divisor )"
64 Arguments: Num.
65
66 Divides the existing number by a number, updating the attribute.
67
68 my $object = My::Class->new( attr => 6 );
69 $object->my_div( 2 );
70 say $object->attr; ## ==> 3
71
72 "eq( $num )"
73 Arguments: Num.
74
75 Returns "$object->attr == $num".
76
77 "ge( $num )"
78 Arguments: Num.
79
80 Returns "$object->attr >= $num".
81
82 "get()"
83 Returns the current value of the number.
84
85 my $object = My::Class->new( attr => 4 );
86 say $object->my_get; ## ==> 4
87
88 "gt( $num )"
89 Arguments: Num.
90
91 Returns "$object->attr > $num".
92
93 "le( $num )"
94 Arguments: Num.
95
96 Returns "$object->attr <= $num".
97
98 "lt( $num )"
99 Arguments: Num.
100
101 Returns "$object->attr < $num".
102
103 "mod( $divisor )"
104 Arguments: Num.
105
106 Finds the current number modulo a divisor, updating the attribute.
107
108 my $object = My::Class->new( attr => 5 );
109 $object->my_mod( 2 );
110 say $object->attr; ## ==> 1
111
112 "mul( $factor )"
113 Arguments: Num.
114
115 Multiplies the existing number by a number, updating the attribute.
116
117 my $object = My::Class->new( attr => 2 );
118 $object->my_mul( 5 );
119 say $object->attr; ## ==> 10
120
121 "ne( $num )"
122 Arguments: Num.
123
124 Returns "$object->attr != $num".
125
126 "set( $value )"
127 Arguments: Num.
128
129 Sets the number to a new value.
130
131 my $object = My::Class->new( attr => 4 );
132 $object->my_set( 5 );
133 say $object->attr; ## ==> 5
134
135 "sub( $subtrahend )"
136 Arguments: Num.
137
138 Subtracts a number from the existing number, updating the attribute.
139
140 my $object = My::Class->new( attr => 9 );
141 $object->my_sub( 6 );
142 say $object->attr; ## ==> 3
143
145 Please report any bugs to
146 <https://github.com/tobyink/p5-sub-handlesvia/issues>.
147
149 Sub::HandlesVia.
150
152 Toby Inkster <tobyink@cpan.org>.
153
155 This software is copyright (c) 2020, 2022 by Toby Inkster.
156
157 This is free software; you can redistribute it and/or modify it under
158 the same terms as the Perl 5 programming language system itself.
159
161 THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED
162 WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
163 MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
164
165
166
167perl v5.36.0 202S2u-b1:2:-H1a7ndlesVia::HandlerLibrary::Number(3)