Graeme, (Send your messages to the list beginners@perl.org so that more people can help you out.)
I still don't know where your problem is. The files you sent look ok, with some remarks: em_log.pm should contain the statement "package SI::eventmaster::em_log;" rather than "package em_log;" (prevents namespace conflicts) and objects should be created with "SI::eventmaster::em_log->new" instead of "em_log->new" (this is the common convention) em_log.pm should not trust others to load classes for it ("use HTML::Template" in the scope of module). As Shawn said, don't you have other "package em_log;" statement in another file? Take a look at the innards of your object with use Data::Dumper; print Dumper $log Is this what you expect to see? Maybe old code is being invoked and not the one you expect. For example, the statement use SI::event_master::em_log; would cause the file "SI/event_master/em_log.pm" (in the library path) to be read/loaded and not just "em_log.pm". Print something in "em_log.pm" so that you know that the control flow passed through your file. On 6/7/06, Graeme McLaren <[EMAIL PROTECTED]> wrote:
Hi there, when inserting that line of code I get the following printed: em_log I'm using strict and warnings on my script and strict on my class. I've attached the class and the script - might make it easier, I appreciate the help on this. Trying to improve some old code. Cheers, G :)
#class em_log package em_log; use strict; use Data::Dumper; #constructor sub new{ my ($class) = @_; my $self = { _table => undef, _id => undef, # this refers to the column named "pkey_updated_record" in the log table _dbh => undef, }; bless $self, $class; return $self; } #accessor method for em_log table sub table{ my $self = shift; my $table= shift; $self->{_table} = $table if defined($table); return $self->{_table}; } #accessor method for em_log id sub id{ my $self = shift; my $id = shift; $self->{_id} = $id if defined($id); return $self->{_id}; } sub dbh{ my $self = shift; my $dbh = shift; $self->{_dbh} = $dbh if defined($dbh); return $self->{_dbh}; } sub view{ my $self=shift; my $dbh = $self->dbh; # my $sth = $dbh->prepare('SELECT date_record_changed, message, user_id FROM log WHERE pkey_updated_record=1086 ORDER BY date_record_changed DESC'); # $sth->execute; my $log_template_data = []; #while(my $log_data = $sth->fetchrow_hashref){ #print "$log_data->{'message'}"; ## $log_data->{'date_record_changed'} = &SI::eventmaster::stdlib::secs_to_timestamp($log_data->{'date_record_changed'}); ## ## if( $#$log_template_data % 2){ # $log_data->{'odd_even'} = 'odd'; ## $log_data->{'colour'} = $EM_CONF{'odd'}; # $log_data->{'colour'} = "white"; ## }else{ # $log_data->{'odd_even'} = 'even'; ## $log_data->{'colour'} = $EM_CONF{'even'}; # $log_data->{'colour'} = "white"; ## } ## my $log_data='test'; push @$log_template_data, $log_data; #} #$sth->finish; my $no_log_data = "no log data"; ## ## my $no_log_data=''; # if([EMAIL PROTECTED]){ # $no_log_data='Nothing added to log for this record'; # } ## my $template=HTML::Template->new(filename => '/var/www/mi-eventmaster/html/templates/em/admin/general/view_log.tmpl'); $template->param( VIEW_LOG => $log_template_data, NO_LOG_DATA => $no_log_data, ID => '1086' ); # #print $template->output; } sub print{ my $self = shift; #print Log info # print "<html><head><head><body>"; print( "Log table and id:", $self->table, $self->id); print Dumper($self->dbh); #print "</body></html>"; } 1;
use HTML::Template; use Data::Dumper; use warnings; use strict; use SI::eventmaster::em_log; use CGI qw/:standard :html3/; use CGI::Carp qw(fatalsToBrowser); use SI::eventmaster::stdlib; #print "Content-type: text/html\n\n"; my $dbh = &SI::eventmaster::stdlib::get_db_handle({'dbname' =>'emdbv3', 'sslmode' => 'disable'}); my $log = em_log->new($dbh); print ref $log; $log->dbh($dbh); $log->table('locations'); $log->id('1086'); $log->view; #$log->print;
-- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>