package Foo::People;
use Foo::PersistentObject;
@ISA = 'Foo::PersistentObject';
use strict;
my %ARGS = (
_id => 'people_id',
_table => 'people',
_mapping => {
id => 'people_id',
first_name => 'first',
last_name => 'last'
}
);
sub new {
my ($class,$id) = @_;
$ARGS{_open_this_id} = $id if $id;
my $self = $class->SUPER::new( %ARGS );
}
sub get_list {
my $class = shift;
$class->SUPER::get_list( %ARGS );
}
1;
####
my $person = Foo::People->new;
$person->open( $id );
my $person = Foo::People->new( $id ); # same thing as above
my $people = Foo::People->get_list; # get a list of all people (as objects)
####
sub get_list {
my ($class, %args) = @_;
my ($id_name,$table) = @args{qw(_id _table)};
my $sql = "SELECT $id_name FROM $table";
# the database object is deliberately unavailable to the
# programmers
my @objects;
my $ids = $DBO->_arrayref( $sql );
foreach my $id ( @$ids ) {
push @objects => $class->new(%args,open_id => $id);
}
return \@objects;
}
####
sub new {
my ($class,$id) = @_;
$ARGS{open_id} = $id if $id;
$class->_new( %ARGS );
}
sub _new {
my $class = shift;
$class->SUPER::new( @_ );
}