SPrelewicz
Programmer
I've been using Perl for a bit, but am just starting to use it with objects. I have a code snippet I'd like critiqued to see if I'm on the right track or havent got a clue. I am using CGI::App, but not sure that should matter. Anyway, here's the code:
sub show_form {
my $self=shift;
my $dbh=$self->param('dbh');
my $template=$self->load_tmpl('/HUBNET/stats_front.tmpl');
my $recent_reports=$self->load_recent();
}
sub load_reports {
my $self=shift;
my $dbh=$self->param('dbh')
# Get the list of recent reports run from the database
unless (exists($self->{__RECENT_REPORTS})) {
$self->{__RECENT_REPORTS} = {};
my $sth=$dbh->prepare("SELECT * FROM recent_reports ORDER BY date LIMIT 5");
$sth->execute();
while (my $row=$sth->fetchrow_hashref()) {
$self->{__RECENT_REPORTS}->($row->{report_id})=$row;
}
}
return $self->{__RECENT_REPORTS};
}
It's the start of a stat reporting program. One aspect of the program is that it will show the 5 most recently run reports that are stored in a db. What I want to know is that these two functions follow correct OO principals.
Thanks for the advice,
Scott
sub show_form {
my $self=shift;
my $dbh=$self->param('dbh');
my $template=$self->load_tmpl('/HUBNET/stats_front.tmpl');
my $recent_reports=$self->load_recent();
}
sub load_reports {
my $self=shift;
my $dbh=$self->param('dbh')
# Get the list of recent reports run from the database
unless (exists($self->{__RECENT_REPORTS})) {
$self->{__RECENT_REPORTS} = {};
my $sth=$dbh->prepare("SELECT * FROM recent_reports ORDER BY date LIMIT 5");
$sth->execute();
while (my $row=$sth->fetchrow_hashref()) {
$self->{__RECENT_REPORTS}->($row->{report_id})=$row;
}
}
return $self->{__RECENT_REPORTS};
}
It's the start of a stat reporting program. One aspect of the program is that it will show the 5 most recently run reports that are stored in a db. What I want to know is that these two functions follow correct OO principals.
Thanks for the advice,
Scott