GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages
MooseX::Extended::Manual::Shortcuts(3) User Contributed Perl Documentation MooseX::Extended::Manual::Shortcuts(3)

MooseX::Extended::Manual::Shortcuts - Shortcuts to make your Moose easier to write

version 0.35

When using "field" or "param", we have some attribute shortcuts:

    param name => (
        isa       => NonEmptyStr,
        writer    => 1,   # set_name
        reader    => 1,   # get_name
        predicate => 1,   # has_name
        clearer   => 1,   # clear_name
        builder   => 1,   # _build_name
    );
    sub _build_name ($self) {
        ...
    }

These can also be used when you pass an array reference to the function:

    package Point {
        use MooseX::Extended types => ['Int'];
        param [ 'x', 'y' ] => (
            isa     => Int,
            clearer => 1,     # clear_x and clear_y available
            default => 0,
        );
    }

Note that these are shortcuts and they make attributes easier to write and more consistent. However, you can still use full names:

    field authz_delegate => (
        builder => '_build_my_darned_authz_delegate',
    );

These are very similar to MooseX::AttributeShortcuts <https://metacpan.org/pod/MooseX::AttributeShortcuts>, but the naming is slightly different. For example, "clearer => 1" for a "_name" attribute creates a "clear__name" method. but for "MooseX::AttributeShortcuts", it would have been named "_clear_name".

You still have the "has" function available for defining attributes, but it is unchanged. These shortcuts will not work.

If an attribute has "writer" is set to 1 (the number one), a method named "set_$attribute_name" is created.

This:

    param title => (
        isa       => Undef | NonEmptyStr,
        default   => undef,
        writer => 1,
    );

Is the same as this:

    has title => (
        is      => 'rw',                  # we change this from 'ro'
        isa     => Undef | NonEmptyStr,
        default => undef,
        writer  => 'set_title',
    );

By default, the reader (accessor) for the attribute is the same as the name. You can always change this:

    has payload => ( is => 'ro', reader => 'the_payload' );

However, if you want to change the reader name

If an attribute has "reader" is set to 1 (the number one), a method named "get_$attribute_name" is created.

This:

    param title => (
        isa       => Undef | NonEmptyStr,
        default   => undef,
        reader => 1,
    );

Is the same as this:

    has title => (
        is      => 'rw',                  # we change this from 'ro'
        isa     => Undef | NonEmptyStr,
        default => undef,
        reader  => 'get_title',
    );

If an attribute has "predicate" is set to 1 (the number one), a method named "has_$attribute_name" is created.

This:

    param title => (
        isa       => Undef | NonEmptyStr,
        default   => undef,
        predicate => 1,
    );

Is the same as this:

    has title => (
        is        => 'ro',
        isa       => Undef | NonEmptyStr,
        default   => undef,
        predicate => 'has_title',
    );

If an attribute has "clearer" is set to 1 (the number one), a method named "clear_$attribute_name" is created.

This:

    param title => (
        isa     => Undef | NonEmptyStr,
        default => undef,
        clearer => 1,
    );

Is the same as this:

    has title => (
        is      => 'ro',
        isa     => Undef | NonEmptyStr,
        default => undef,
        clearer => 'clear_title',
    );

If an attribute has "builder" is set to 1 (the number one), a method named "_build_$attribute_name".

This:

    param title => (
        isa     =>  NonEmptyStr,
        builder => 1,
    );

Is the same as this:

    has title => (
        is      => 'ro',
        isa     => NonEmptyStr,
        builder => '_build_title',
    );

Obviously, a "private" attribute, such as "_auth_token" would get a build named "_build__auth_token" (note the two underscores between "build" and "auth_token").

    param name => ( is => 'rwp' );

The above is equivalent to:

    has name => ( is => 'ro', writer => '_set_name' );

Of course, it works for "field", too.

You may also pass a coderef to `builder`:

    field created => (
        isa     => PositiveInt,
        lazy    => 0,
        builder => sub {time},
    );

This is different from "default => sub {...}" because it will install a "_build_created" method for you. This is useful if you with to allow a subclass to override this method.

Attributes defined using "param" or "field" which are read-only with no "init_arg" and no default or builder, will result in a warning. If you wish to disable this warning you can.

  no warnings 'MooseX::Extended::naked_fields';

This warning is only available on Perl >= 5.028.

Curtis "Ovid" Poe <curtis.poe@gmail.com>

This software is Copyright (c) 2022 by Curtis "Ovid" Poe.

This is free software, licensed under:

  The Artistic License 2.0 (GPL Compatible)
2023-06-06 perl v5.40.2

Search for    or go to Top of page |  Section 3 |  Main Index

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with ManDoc.