Scroll to navigation

Object::Pad::SlotAttr::Trigger(3pm) User Contributed Perl Documentation Object::Pad::SlotAttr::Trigger(3pm)

NAME

"Object::Pad::SlotAttr::Trigger" - invoke an instance method after a ":writer" accessor

SYNOPSIS

   use Object::Pad;
   use Object::Pad::SlotAttr::Trigger;
   class Label {
      has $title :param :reader :writer :Trigger(redraw);
      method redraw {
         ...
      }
   }
   my $label = Label->new( text => "Something" );
   $label->set_label( "New text here" );
   # $label->redraw is automatically invoked

DESCRIPTION

This module provides a third-party slot attribute for Object::Pad-based classes, which declares that a named instance method shall be invoked after a generated ":writer" accessor method is called.

WARNING The ability for Object::Pad to take third-party slot attributes is still new and highly experimental, and subject to much API change in future. As a result, this module should be considered equally experimental.

SLOT ATTRIBUTES

:Trigger

   has $slot :writer :Trigger(NAME) ...;

Declares that the accessor method generated for the slot by the ":writer" attribute will invoke the method named by the ":Trigger" attribute, after the new value has been stored into the slot itself. This method is invoked with no additional arguments, in void context.

Note that this only applies to the generated accessor method. It does not apply to direct modifications of the slot variable by method code within the class itself.

AUTHOR

Paul Evans <leonerd@leonerd.org.uk>

2022-02-07 perl v5.34.0