line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# You may distribute under the terms of either the GNU General Public License |
2
|
|
|
|
|
|
|
# or the Artistic License (the same terms as Perl itself) |
3
|
|
|
|
|
|
|
# |
4
|
|
|
|
|
|
|
# (C) Paul Evans, 2021-2023 -- leonerd@leonerd.org.uk |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
package Object::Pad::FieldAttr::Trigger 0.07; |
7
|
|
|
|
|
|
|
|
8
|
2
|
|
|
2
|
|
241184
|
use v5.14; |
|
2
|
|
|
|
|
13
|
|
9
|
2
|
|
|
2
|
|
11
|
use warnings; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
54
|
|
10
|
|
|
|
|
|
|
|
11
|
2
|
|
|
2
|
|
515
|
use Object::Pad 0.66; |
|
2
|
|
|
|
|
8776
|
|
|
2
|
|
|
|
|
122
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
require XSLoader; |
14
|
|
|
|
|
|
|
XSLoader::load( __PACKAGE__, our $VERSION ); |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
=head1 NAME |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
C - invoke an instance method after a C<:writer> accessor |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
=head1 SYNOPSIS |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
use Object::Pad; |
23
|
|
|
|
|
|
|
use Object::Pad::FieldAttr::Trigger; |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
class Label { |
26
|
|
|
|
|
|
|
field $title :param :reader :writer :Trigger(redraw); |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
method redraw { |
29
|
|
|
|
|
|
|
... |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
my $label = Label->new( text => "Something" ); |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
$label->set_label( "New text here" ); |
36
|
|
|
|
|
|
|
# $label->redraw is automatically invoked |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
=head1 DESCRIPTION |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
This module provides a third-party field attribute for L-based |
41
|
|
|
|
|
|
|
classes, which declares that a named instance method shall be invoked after |
42
|
|
|
|
|
|
|
a generated C<:writer> accessor method is called. |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
B The ability for L to take third-party field attributes |
45
|
|
|
|
|
|
|
is still new and highly experimental, and subject to much API change in |
46
|
|
|
|
|
|
|
future. As a result, this module should be considered equally experimental. |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
=head1 FIELD ATTRIBUTES |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
=head2 :Trigger |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
field $name :writer :Trigger(NAME) ...; |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
Declares that the accessor method generated for the field by the C<:writer> |
55
|
|
|
|
|
|
|
attribute will invoke the method named by the C<:Trigger> attribute, after the |
56
|
|
|
|
|
|
|
new value has been stored into the field itself. This method is invoked with |
57
|
|
|
|
|
|
|
no additional arguments, in void context. |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
Note that this only applies to the generated accessor method. It does not |
60
|
|
|
|
|
|
|
apply to direct modifications of the field variable by method code within the |
61
|
|
|
|
|
|
|
class itself. |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
=cut |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
sub import |
66
|
|
|
|
|
|
|
{ |
67
|
1
|
|
|
1
|
|
88
|
$^H{"Object::Pad::FieldAttr::Trigger/Trigger"}++; |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
sub unimport |
71
|
|
|
|
|
|
|
{ |
72
|
0
|
|
|
0
|
|
|
delete $^H{"Object::Pad::FieldAttr::Trigger/Trigger"}; |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
=head1 AUTHOR |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
Paul Evans |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
=cut |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
0x55AA; |