NAME

ODG::Layout - Container role for managing metadata

SYNOPSIS

package My::Layout;
use Moose;
  with 'ODG::Layout';

  ...install additional attributes, methods and logic...


package main;

  my $layout = My::Layout->new( { 
      _metadata_ => [ 
          ODG::Metadata->new( { name => 'field_1'  ] ,
          ODG::Metadata->new( { name => 'field_2'  ] ,
      ]
  } );

# Access the metadata.
  $layout->_metadata_->[0];
  $layout->get(0);
  $layout->field_1;

...

DESCRIPTION

ODG::Layout is an container role that defines a record layout. It containter ODG::Metadata objects in an ArrayRef slot called _metadata_. When the slot is populated or changed, two things occur

  • an b<index> attribute is added to each of the ODG::Metadata objects. The index attribute indicates the fields position within the layout.

  • named based accessors are installed for each of the ODG::Metadata objects

    ODG::Layout is part of the ODG::Record distribution. Here is an object model

    ODG::Record
      |
      |- slot: _data_
      |
      |- slot: _layout_ (container for ODG::Metadata objects )
      |    |
      |    |- slot: _metadata_
      |
      |- slot: _metadata_  ( Refs ODG::Record::_layout_::_metadata_ ) 

SLOTS

_metadata_

ArrayRef[ODG::Metadata] with metaclass Collection::Array.

Standard array methods ( push, pop, shift, ... ) operating on the derived class operate on this slot. The slot can also be accessed with the _metadata_ accessor.

ATTRIBUTES

_index_name

Private. Str. What the attribute is called that is installed in each of the ODG::Metadata objects in _metadata_ slot.

PUBLIC METHODS

new

Constructor method. Can optionally take a _metadata_ Attribute ArrayRef Installs name based accessors. Additionally, installs an index attribute into each of the ODG::Metadata objects in the _metadata_ slot. This allows for accessing the position of the field by name.

Accessor Methods

The _metadata_ can be accessed by name or by position.

# Name based.
$layout->field_1;         # Return the ODG::Metadata object
$layout->field_1->name;   # field_1
$layout->field_1->index;  # Position in layout.

# Position based
$layout->_metadata_->[0];      # Returns the first field.
$layout->get(0);               # Same using MooseX::AttributeHelpers

TODO: push, pop, shift, unshift, insert

This permits the layout defintiion to be built one field at a time or cloned and modified.

See MooseX::AttributeHelpers

TODO: clear, delete, empty

See MooseX::AttributeHelpers

count

See MooseX::AttributeHelpers

grep, map, find

See MooseX::AttributeHelpers

PRIVATE METHODS

_create_index

Installs an b<index> attribute in each of each ODG::Metadata object in the _metadata_ slot. The value of the index is the position in that slot.

_install_named_accessors

Installs named based accessors to ODG::Metadata objects in the _metadata_ slot. One accessor is defined and named for each ODG::Metadata object.

TODO

  • Private method return values

    Should we provide a return value (T/F) for succes of the private methods.

  • Enforce unique metadata names(?)

Extending

package My::Layout;
use Moose;
    with 'ODG::Layout';

SEE ALSO

ODG::Metadata, ODG::Record, Moose, MooseX::AttributeHelpers;

THANKS

Steven Little, author of Moose

Members of moose@perl.org

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.

4 POD Errors

The following errors were encountered while parsing the POD:

Around line 183:

'=item' outside of any '=over'

Around line 204:

You forgot a '=back' before '=head1'

Around line 287:

'=item' outside of any '=over'

Around line 294:

You forgot a '=back' before '=head1'