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
MouseX::AttributeHelpers(3) User Contributed Perl Documentation MouseX::AttributeHelpers(3)
 

MouseX::AttributeHelpers - Extend your attribute interfaces

    package MyClass;
    use Mouse;
    use MouseX::AttributeHelpers;
    has 'mapping' => (
        metaclass => 'Collection::Hash',
        is        => 'rw',
        isa       => 'HashRef',
        default   => sub { +{} },
        provides  => {
            exists => 'exists_in_mapping',
            keys   => 'ids_in_mapping',
            get    => 'get_mapping',
            set    => 'set_mapping',
        },
    );
    package main;
    my $obj = MyClass->new;
    $obj->set_quantity(10);      # quantity => 10
    $obj->set_mapping(4, 'foo'); # 4 => 'foo'
    $obj->set_mapping(5, 'bar'); # 5 => 'bar'
    $obj->set_mapping(6, 'baz'); # 6 => 'baz'
    # prints 'bar'
    print $obj->get_mapping(5) if $obj->exists_in_mapping(5);
    # prints '4, 5, 6'
    print join ', ', $obj->ids_in_mapping;

MouseX::AttributeHelpers provides commonly used attribute helper methods for more specific types of data.
As seen in the "SYNOPSIS", you specify the extension via the "metaclass" parameter.

This points to a hashref that uses "provider" for the keys and "method" for the values. The method will be added to the object itself and do what you want.

This points to a hashref that uses "provider" for the keys and has two choices for the value:
You can supply "{ method => \@args }" for the values. The method will be added to the object itself (always using @args as the beginning arguments).
Another approach to curry a method provider is to supply a coderef instead of an arrayref. The code ref takes $self, $body, and any additional arguments passed to the final method.

Methods for incrementing and decrementing a counter attribute.

Common numerical operations.

Common methods for string values.

Common methods for boolean values.

Common list methods for array references.

Common methods for array references.

Common methods for hash references.

Common additional methods for hash references.

Methods for incrementing and decrementing a value of collection.

NAKAGAWA Masaki <masaki@cpan.org>

"AUTHOR" in MooseX::AttributeHelpers

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

Mouse
MouseX::AttributeHelpers::Counter, MouseX::AttributeHelpers::Number, MouseX::AttributeHelpers::String, MouseX::AttributeHelpers::Bool, MouseX::AttributeHelpers::Collection::List, MouseX::AttributeHelpers::Collection::Array, MouseX::AttributeHelpers::Collection::ImmutableHash, MouseX::AttributeHelpers::Collection::Hash, MouseX::AttributeHelpers::Collection::Bag
MooseX::AttributeHelpers
2012-05-03 perl v5.28.1

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.