ODG::Record - Perl extension for efficient and simple manipulation of row-based records.
package MyClass; use Moose; extends 'ODG::Record'; has first_name => ( is => 'rw' , isa => 'Str', index => 0 , # Denotes ArrayRef position for attribute traits => [ 'Index' ] , # Required trait ); ... package main; use ODG::Record; my $record = ODG::Record->new( _data => [ 'frank', 'n', 'stein' ] ) ); # Indexed attributes are stored in the ArrayRef and can be accessed # as any other attribute except that print $record->first_name; # frank # Data can retrieved by using the _data attribute. $record->_data = [ 'char', 'lee', 'brown' ] ; $record->first_name; # char # L-value attributes can also be defined. $record->first_name = 'Robert'
THIS VERSION BREAKS BACKWARD WITH PREVIOUS VERSIONS. THE API IS SIMPLIER.
ODG::Record is an extensible Moose-based class for efficiently and simply working with row based records. ArrayRefs are much faster than HashRefs especially for long arrays. This module circumvents the Mooses' HashRef based objects and places designated attributes in the _data slot, an ArrayRef. This allows for construction of more efficient row-based processing but retains the Moose flavor.
To work with a new record, simply change the reference of the _data slot.
$record->_data( [ 'Some', 'Array', 'Ref' ] );
Since the emphasis is on speed and generally connection to tightly typed systems such as Databases, we break the Moose encapsulation and install our own type-checking free accessors. Type checking is left up to the user. Since we have eliminated the type-checking, we have also added another bit of magic, L-based accessors. So rather than coding:
$record->first_name( "Frank" );
You can use the much more natural appearing:
$record->first_name = "Frank"
This only works for attributes that are placed in the ArrayRef. Other attributes have normal Moose behavior.
Placing the record data in an ArrayRef _data slot allows far greater efficient when processing row-based records. Rather than creating a new object for each row, ODG::Record recycles the object and only swaps the reference of the _data. Since data is stored as an ArrayRef, this is a huge performance win.
During object construction, name-based accessors are built for each record field. By default, the accessors permit L-value assignment.
Object constructor. Creates and returns a ODG::Record object. It takes the following options.
L-value object accessor to the record data. Data is stroed internally as an array reference, so data This is the very fast accessor for the _data,
# Getter $record->_data # Retrieve entire array ref $record->_data->[ $index ] # Get a specific field # Setter $record->_data( [ .. ] ) $record->_data = [ .. ] $record->_data->[ $index ] = $value
None by default.
Steven Little, author of Moose
Paul Driver for suggesting to place the accessor methods in the instance rather than the class.
Members of firstname.lastname@example.org.
Christopher Brown, <http://www.opendatagroup,com>
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.