DBIx::Simple::OO
use DBIx::Simple; use DBIx::Simple::OO; # adds OO methods $db = DBIx::Simple->connect( ... ); $query = 'select id,name,age from people'; $res = $db->query( $query ); $obj = $res->object; @obj = $res->objects; $id = $obj->id; # get the value for field 'id' $name = $obj->name; # get the value for field 'name' $age = $obj->age; # get the value for field 'age' @acc = $obj->ls_accessors; # get a list of all fields $sub = $obj->can('name'); # check if this object has a # 'name' method ### add a method to every object that will be returned ### by DBIx::Simple::OO { package DBIx::Simple::OO::Item; sub has_valid_id { return shift->id !~ /\D/ ? 1 : 0 } } $bool = $obj->has_valid_id;
This module provides a possibility to retrieve rows from a database as objects, rather than the traditional array ref or hash ref. This provides all the usual benefits of using objects over plain references for accessing data, as well as allowing you to add methods of your own choosing for data retrieval.
array ref
hash ref
DBIx::Simple::OO declares it's 2 methods in the DBIx::Simple::Result namespace, transforming the rows retrieved from the database to full fledged objects.
DBIx::Simple::Result
This module subclasses DBIx::Simple and only adds the following methods. Any other method, like the new call should be looked up in the DBIx::Simple manpage instead.
DBIx::Simple
new
Returns the first result from your query as an object.
Returns the results from your query as a list of objects.
All objects returned by the above methods are from the DBIx::Simple::OO::Item class, which subclasses Object::Accessor.
DBIx::Simple::OO::Item
Object::Accessor
The most important methods are described in the synopsis, but you should refer to the Object::Accessor manpage for more extensive documentation.
Note that it is possible to declare methods into the DBIx::Simple::OO::Item class to extend the functionality of the objects returned by DBIx::Simple::OO, as also described in the SYNOPSIS
SYNOPSIS
This module by Jos Boumans <kane@cpan.org>.
This module is copyright (c) 2005 Jos Boumans <kane@cpan.org>. All rights reserved.
This library is free software; you may redistribute and/or modify it under the same terms as Perl itself.
To install DBIx::Simple::OO, copy and paste the appropriate command in to your terminal.
cpanm
cpanm DBIx::Simple::OO
CPAN shell
perl -MCPAN -e shell install DBIx::Simple::OO
For more information on module installation, please visit the detailed CPAN module installation guide.