Catmandu::Fix::Has(3pm)

Catmandu::Fix::Has3pm

Helper class for creating fix-es with (optional) parameters

Usage

    package Catmandu::Fix::foo;
    use Moo;
    use Catmandu::Fix::Has;
    has greeting => (fix_arg => 1);   # required parameter 1
    has message  => (fix_arg => 1);   # required parameter 2
    has eol      => (fix_opt => 1 , default => sub {'!'} ); # optional parameter 'eol' with default '!'
    sub fix {
        my ($self,$data) = @_;
        print STDERR $self->greeting . ", " . $self->message . $self->eol . "\n";
        $data;
    }
    1;

Parameters

fix_arg

Required argument when set to 1. The Fix containing the code fragment below needs two arguments.

    use Catmandu::Fix::Has;
    has message => (fix_arg => 1); # required parameter 1
    has number  => (fix_arg => 1); # required parameter 2

When the fix_arg is set to 'collect', then all arguments are read into an array. The Fix containing the code fragment below needs at least 1 or more arguments. All arguments will get collected into the "messages" array:

    use Catmandu::Fix::Has;
    has messages => (fix_arg => 'collect'); # required parameter
fix_opt

Optional named argument when set to 1. The Fix containing the code fragment below can have two optional arguments "message: ...", "number: ...":

    use Catmandu::Fix::Has;
    has message => (fix_opt => 1); # optional parameter 1
    has number  => (fix_opt => 1); # optional parameter 2

When the fix_opt is set to 'collect', then all optional argument are read into an array. The Fix containing the code fragment below needs at least 1 or more arguments. All arguments will get collected into the "options" array:

    use Catmandu::Fix::Has;
    has options => (fix_opt => 'collect'); # optional parameter

Releases

6 releases since Debian 8 (Jessie); the text changed 5 times.

  1. 8
  2. 9
  3. 10
  4. 11
  5. 12
  6. 13

From libcatmandu-perl 1.2024-1 in Debian 13 (Trixie). Parsed by carta from the page's man source.