NAME

MooseX::Meta::Attribute::Index

SYNOPSIS

package App;
    use Moose;
        with 'MooseX::Meta::Attribute::Index';

    has attr_1 => ( 
        traits  => [ qw/Index/ ] ,
        is      => 'rw'     , 
        isa     => 'Str'    ,
        index   => 0
    );

    has attr_2 => (
        traits  => [ qw/Index/ ] ,
        is      => 'rw'     ,
        isa     => 'Int'    ,
        index   => 1
    ) ;


package main;
    my $app = App->new( attr_1 => 'foo', attr_2 => 42 );
    
    $app->meta->get_attribute_index( "attr_1" );  # 0
    $app->meta->get_attribute_index( "attr_2" );  # 1

DESCRIPTION

Implements a meta-attribute, index, using traits. The index meta attribute is used for providing ordering of attributes. This is useful in situations where the order of attributes matters. For example, see ODG::Record where maintaining of the order of attributes allows for a Moose-based record iterator.

The indexes must be defined and provided manually. The indexs are checked to ensure that negative indices are not used.

In addition to the meta-attribute, a Moose::Meta::Class method, get_attribute_index is provided to retrieve the indices of an attribute.

METHODS

Moose::Meta::Class::get_attribute_index( $attr_name )

Returns the index for the named attribute.

SEE ALSO

ODG::Record, Moose

AUTHOR

Christopher Brown, <http://www.opendatagroup,com>

COPYRIGHT AND LICENSE

Copyright (C) 2008 by Open Data

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.10.0 or, at your option, any later version of Perl 5 you may have available.