Sebastian Willing > Tie-DBIx-Class > Tie::DBIx::Class

Download:
Tie-DBIx-Class-0.01.tar.gz

Dependencies

Annotate this POD

CPAN RT

New  1
Open  0
View/Report Bugs
Module Version: 0.01   Source  

NAME ^

Tie::DBIx::Class - Tie a DBIx::Class ResultSet into a hash

VERSION ^

Version 0.01

SYNOPSIS ^

  my $object = Tie::DBIx::Class->new(
      foo  => 'bar',
      flag => 1,
  );

DESCRIPTION ^

This module ties a DBIx::Class::ResultSet into a simple hash but loads the referenced DBIx::Class::ResultSet only on request reducing database access.

DBIx::Class puts a SQL row into a simple object and masks all SQL from you scripts, but it's strictly database based.

Imagine you got a house:

my $house = House->new(1); $house->open_door();

$house could be a SQL row, but what if you'ld like to add methods or sub-objects which aren't SQL rows?

Here is what Tie-DBIx-Class is for:

package House;

sub new { my $class = shift; my $house_id = shift; tie(my %row,'Tie::DBIx::Class',$main::schema,'houses',$house_id); return bless \%row,$class; }

sub open_door { # Access the door controller }

Every column is accessible as a hash key of the blessed object while you're still free to define additional methods.

In addition, Tie::DBIx::Class waits for the first access to the hash's data before actually fetching the data from the database - saving resources in case you just want to open the door and don't need the SQL row's data at all.

Tie::DBIx::Class has been developed for use with Template::Toolkit. Templates may get access to database rows without the need to preload everything which might be used by a template. Just create the objects and push them to Template::Toolkit and the required rows will be loaded automatically.

METHODS ^

TIEHASH

  tie %hashname,'Tie::DBIx::Class',$dbh,$table_name,$primary_key);

The new constructor lets you create a new Tie::DBIx::Class object.

So no big surprises there...

DELETE

Remove the value for a key.

EXISTS

Check if a keys exists.

FETCH

Called for every read access to the tied hash.

FIRSTKEY

Start a new keys() loop.

NEXTKEY

Return a key for the keys() listing.

STORE

Called for every write access to the tied hash.

UNTIE

Commit changes to database.

INTERNAL METHODS ^

_CHECK_DBIx

Check if the DBIx::Class::ResultSet was fetched before.

AUTHOR ^

Copyright 2010 Sebastian Willing

BUGS ^

Please report any bugs or feature requests to bug-tie-dbix-class at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Tie-DBIx-Class. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.

TODO ^

Most important things to do: - Improve error handling

Nice to have: - Allow ->search instead of ->find

SUPPORT ^

You can find documentation for this module with the perldoc command.

    perldoc Tie::DBIx::Class

You can also look for information at:

ACKNOWLEDGEMENTS ^

COPYRIGHT & LICENSE ^

Copyright 2010 Sebastian Willing, all rights reserved.

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

syntax highlighting: