jammy (3) Object::Pad::ClassAttr::Struct.3pm.gz

Provided by: libobject-pad-classattr-struct-perl_0.03-1build1_amd64 bug

NAME

       "Object::Pad::ClassAttr::Struct" - declare an "Object::Pad" class to be struct-like

SYNOPSIS

          use Object::Pad;
          use Object::Pad::ClassAttr::Struct;

          class Colour :Struct {
             # These get :param :mutator automatically
             has $red   = 0;
             has $green = 0;
             has $blue  = 0;

             # Additional methods are still permitted
             method lightness {
                return ($red + $green + $blue) / 3;
             }
          }

          my $cyan = Colour->new( green => 1, blue => 1 );

DESCRIPTION

       This module provides a third-party class attribute for Object::Pad-based classes, which applies some
       attributes automatically to every field added to the class, as a convenient shortcut for making
       structure-like classes.

CLASS ATTRIBUTES

   :Struct
          class Name :Struct ... { ... }

       Automatically applies the ":param" and ":mutator" attributes to every field defined on the class, meaning
       the constructor will accept parameters for each field to initialise the value, and each field will have
       an lvalue mutator method.

       In addition, the class itself gains the ":strict(params)" attribute, meaning the constructor will check
       parameter names and throw an exception for unrecognised names.

AUTHOR

       Paul Evans <leonerd@leonerd.org.uk>