File Coverage

blib/lib/Object/Pad/SlotAttr/Trigger.pm
Criterion Covered Total %
statement 9 9 100.0
branch n/a
condition n/a
subroutine 4 4 100.0
pod n/a
total 13 13 100.0


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 -- leonerd@leonerd.org.uk
5              
6             package Object::Pad::SlotAttr::Trigger 0.05;
7              
8 2     2   68716 use v5.14;
  2         13  
9 2     2   8 use warnings;
  2         4  
  2         51  
10              
11 2     2   778 use Object::Pad 0.50;
  2         8003  
  2         8  
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::SlotAttr::Trigger;
24              
25             class Label {
26             has $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 slot 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 slot 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 SLOT ATTRIBUTES
49              
50             =head2 :Trigger
51              
52             has $slot :writer :Trigger(NAME) ...;
53              
54             Declares that the accessor method generated for the slot 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 slot itself. This method is invoked with no
57             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 slot variable by method code within the
61             class itself.
62              
63             =cut
64              
65             sub import
66             {
67 2     2   94 $^H{"Object::Pad::SlotAttr::Trigger/Trigger"}++;
68             }
69              
70             =head1 AUTHOR
71              
72             Paul Evans
73              
74             =cut
75              
76             0x55AA;