How to wrap DBI $sth object?

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!


I want to make a module that execute the query and return the $sth in
wrapped form.

If you don't use the wrapper it would be like this:
my $sth = $dbh->prepare("SELECT member_id, item_name FROM item");
while (my $row = $sth->fetchrow_arrayref()) {
   print $row->[0];
   pirnt $row->[1];

I want to wrap that, so I can write it like below:
use Item;
my $it = Item::->new();
my $obj = $it->get_items(); ## This return $sth in wrapped form
while (my $item = $obj->each()) {
    print $item->member_id();
    print $item->item_name();
    ## etc

How should I write, so it can be used as the wrapper above?
Could you please give some simple example, as I don't know where to
start. And thank you in advance.


Site Timeline