File: Number.pod

package info (click to toggle)
libsub-handlesvia-perl 0.052000-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,740 kB
  • sloc: perl: 9,645; makefile: 2
file content (193 lines) | stat: -rw-r--r-- 4,030 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
=head1 NAME

Sub::HandlesVia::HandlerLibrary::Number - library of number-related methods

=head1 SYNOPSIS

  package My::Class {
    use Moo;
    use Sub::HandlesVia;
    use Types::Standard 'Num';
    has attr => (
      is => 'rwp',
      isa => Num,
      handles_via => 'Number',
      handles => {
        'my_abs' => 'abs',
        'my_add' => 'add',
        'my_ceil' => 'ceil',
        'my_cmp' => 'cmp',
        'my_div' => 'div',
        'my_eq' => 'eq',
        'my_floor' => 'floor',
        'my_ge' => 'ge',
        'my_get' => 'get',
        'my_gt' => 'gt',
        'my_le' => 'le',
        'my_lt' => 'lt',
        'my_mod' => 'mod',
        'my_mul' => 'mul',
        'my_ne' => 'ne',
        'my_set' => 'set',
        'my_sub' => 'sub',
      },
    );
  }

=head1 DESCRIPTION

This is a library of methods for L<Sub::HandlesVia>.

=head1 DELEGATABLE METHODS

=head2 C<< abs() >>

Finds the absolute value of the current number, updating the attribute.

  my $object = My::Class->new( attr => -5 );
  $object->my_abs;
  say $object->attr; ## ==> 5

=head2 C<< add( $addend ) >>

Arguments: B<< Num >>.

Adds a number to the existing number, updating the attribute.

  my $object = My::Class->new( attr => 4 );
  $object->my_add( 5 );
  say $object->attr; ## ==> 9

=head2 C<< ceil() >>

Finds the ceiling of the current number, updating the attribute. Like C<ceil> from L<builtin>, but in-place.

=head2 C<< cmp( $num ) >>

Arguments: B<< Num >>.

Returns C<< $object->attr <=> $num >>.

=head2 C<< div( $divisor ) >>

Arguments: B<< Num >>.

Divides the existing number by a number, updating the attribute.

  my $object = My::Class->new( attr => 6 );
  $object->my_div( 2 );
  say $object->attr; ## ==> 3

=head2 C<< eq( $num ) >>

Arguments: B<< Num >>.

Returns C<< $object->attr == $num >>.

=head2 C<< floor() >>

Finds the floor of the current number, updating the attribute. Like C<floor> from L<builtin>, but in-place.

=head2 C<< ge( $num ) >>

Arguments: B<< Num >>.

Returns C<< $object->attr >= $num >>.

=head2 C<< get() >>

Returns the current value of the number.

  my $object = My::Class->new( attr => 4 );
  say $object->my_get; ## ==> 4

=head2 C<< gt( $num ) >>

Arguments: B<< Num >>.

Returns C<< $object->attr > $num >>.

=head2 C<< le( $num ) >>

Arguments: B<< Num >>.

Returns C<< $object->attr <= $num >>.

=head2 C<< lt( $num ) >>

Arguments: B<< Num >>.

Returns C<< $object->attr < $num >>.

=head2 C<< mod( $divisor ) >>

Arguments: B<< Num >>.

Finds the current number modulo a divisor, updating the attribute.

  my $object = My::Class->new( attr => 5 );
  $object->my_mod( 2 );
  say $object->attr; ## ==> 1

=head2 C<< mul( $factor ) >>

Arguments: B<< Num >>.

Multiplies the existing number by a number, updating the attribute.

  my $object = My::Class->new( attr => 2 );
  $object->my_mul( 5 );
  say $object->attr; ## ==> 10

=head2 C<< ne( $num ) >>

Arguments: B<< Num >>.

Returns C<< $object->attr != $num >>.

=head2 C<< set( $value ) >>

Arguments: B<< Num >>.

Sets the number to a new value.

  my $object = My::Class->new( attr => 4 );
  $object->my_set( 5 );
  say $object->attr; ## ==> 5

=head2 C<< sub( $subtrahend ) >>

Arguments: B<< Num >>.

Subtracts a number from the existing number, updating the attribute.

  my $object = My::Class->new( attr => 9 );
  $object->my_sub( 6 );
  say $object->attr; ## ==> 3

=head1 BUGS

Please report any bugs to
L<https://github.com/tobyink/p5-sub-handlesvia/issues>.

=head1 SEE ALSO

L<Sub::HandlesVia>.

=head1 AUTHOR

Toby Inkster E<lt>tobyink@cpan.orgE<gt>.

=head1 COPYRIGHT AND LICENCE

This software is copyright (c) 2020, 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.

=head1 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.