Text::RecordParser::Object - read delimited text files as objects


Text-RecordParser documentation Contained in the Text-RecordParser distribution.

Index


Code Index:

NAME

Top

Text::RecordParser::Object - read delimited text files as objects

SYNOPSIS

Top

  my $o = $p->fetchrow_object;
  my $name = $o->name;

METHOD

Top

new

Just call "fetchrow_object" on a Text::RecordParser object to instantiate an object.

DESCRIPTION

Top

This module extends the idea of how you interact with delimited text files, allowing you to enforce field names and identify field aliases easily. That is, if you are using the "fetchrow_hashref" method to read each line, you may misspell the hash key and introduce a bug in your code. With this module, Perl will throw an error if you attempt to read a field not defined in the file's headers. Additionally, any defined field aliases will be created as additional accessor methods.

As much as I like the full encapsulation of inside-out objects (e.g., as described in _Perl Best Practies_ by Damian Conway and provided by Class::Std), I couldn't figure out a way to dynamically create the class at runtime. Besides, I figure this interface is only for those who want to use the overhead of objects to enforce policy. If you use this module and still access the hash underneath the object, I can't really help you.

SEE ALSO

Top

Class::Accessor.

AUTHOR

Top

Ken Youens-Clark <kclark@cpan.org>

LICENSE AND COPYRIGHT

Top


Text-RecordParser documentation Contained in the Text-RecordParser distribution.

package Text::RecordParser::Object;

use strict;
use warnings;
use version;

use base qw( Class::Accessor );

our $VERSION = version->new('1.4.0');

sub new {
    my ( $class, $field_names, $self ) = @_;
    $class->mk_ro_accessors( @$field_names );
    bless $self, $class;
    return $self;
}

1;

__END__

# ----------------------------------------------------------------