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

MouseX::NativeTraits - Extend your attribute interfaces for Mouse

This document describes MouseX::NativeTraits version 1.09.

    package MyClass;
    use Mouse;

    has mapping => (
        traits    => ['Hash'],
        is        => 'rw',
        isa       => 'HashRef[Str]',
        default   => sub { +{} },
        handles   => {
            exists_in_mapping => 'exists',
            ids_in_mapping    => 'keys',
            get_mapping       => 'get',
            set_mapping       => 'set',
            set_quantity      => [ set => 'quantity' ],
        },
    );

While Mouse attributes provide a way to name your accessors, readers, writers, clearers and predicates, MouseX::NativeTraits provides commonly used attribute helper methods for more specific types of data.

As seen in the "SYNOPSIS", you specify the data structure via the "traits" parameter. These traits will be loaded automatically, so you need not load MouseX::NativeTraits explicitly.

This extension is compatible with Moose native traits, although it is not a part of Mouse core.

This is like "handles" in "has" in Mouse, but only HASH references are allowed. Keys are method names that you want installed locally, and values are methods from the method providers (below). Currying with delegated methods works normally for "handles".

Common methods for array references.

    has 'queue' => (
       traits     => ['Array'],
       is         => 'ro',
       isa        => 'ArrayRef[Str]',
       default    => sub { [] },
       handles    => {
           add_item  => 'push',
           next_item => 'shift',
       }
    );

See MouseX::NativeTraits::ArrayRef.

Common methods for hash references.

    has 'options' => (
        traits    => ['Hash'],
        is        => 'ro',
        isa       => 'HashRef[Str]',
        default   => sub { {} },
        handles   => {
            set_option => 'set',
            get_option => 'get',
            has_option => 'exists',
        }
    );

See MouseX::NativeTraits::HashRef.

Common methods for code references.

    has 'callback' => (
       traits     => ['Code'],
       is         => 'ro',
       isa        => 'CodeRef',
       default    => sub { sub { 'called' } },
       handles    => {
           call => 'execute',
       }
    );

See MouseX::NativeTraits::CodeRef.

Common methods for boolean values.

    has 'is_lit' => (
        traits    => ['Bool'],
        is        => 'rw',
        isa       => 'Bool',
        default   => 0,
        handles   => {
            illuminate  => 'set',
            darken      => 'unset',
            flip_switch => 'toggle',
            is_dark     => 'not',
        }
    );

See MouseX::NativeTraits::Bool.

Common methods for string operations.

    has text => (
        traits    => ['String'],
        is        => 'rw',
        isa       => 'Str',
        default   => q{},
        handles   => {
            add_text     => 'append',
            replace_text => 'replace', # or replace_globally
        }
    );

See MouseX::NativeTraits::Str.

Common numerical operations.

    has value => (
        traits    => ['Number'],
        is        => 'ro',
        isa       => 'Int',
        default   => 5,
        handles   => {
            set => 'set',
            add => 'add',
            sub => 'sub',
            mul => 'mul',
            div => 'div',
            mod => 'mod',
            abs => 'abs',
        }
    );

See MouseX::NativeTraits::Num.

Methods for incrementing and decrementing a counter attribute.

    has counter => (
        traits    => ['Counter'],
        is        => 'ro',
        isa       => 'Num',
        default   => 0,
        handles   => {
            inc_counter   => 'inc',
            dec_counter   => 'dec',
            reset_counter => 'reset',
        }
    );

See MouseX::NativeTraits::Counter.

Perl 5.6.2 or later.

All complex software has bugs lurking in it, and this module is no exception. If you find a bug please either email me, or add the bug to cpan-RT.

Mouse

MouseX::AttributeHelpers

Moose

Moose::Meta::Attribute::Native

MooseX::AttributeHelpers

Goro Fuji (gfx) <gfuji(at)cpan.org>

This module is based on Moose native traits written by Stevan Little and others.

Copyright (c) 2010, Goro Fuji (gfx), mostly based on Moose, which is (c) Infinity Interactive, Inc (<http://www.iinteractive.com>).

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

2012-11-26 perl v5.32.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.