EPrints Technical Mailing List Archive

Message: #02493


< Previous (by date) | Next (by date) > | < Previous (in thread) | Next (in thread) > | Messages - Most Recent First | Threads - Most Recent First

[EP-tech] Re: Adding methods to EPrints::Database


Maybe you're missing "use EPrints::DataObj::VisitorTickets;" in your
script (or in some module which is used by your script).

Besides of that, you'll probably be safer with the following:

package EPrints::Database;
sub update_visitor_ticket { ... }

rather than

sub EPrints::Database::update_visitor_ticket { ... }

See http://perldoc.perl.org/perlmod.html (search for Some_package::foo)
for an explanation of the nuances.

Ian Stuart wrote:
> OK, I'm doing "hinky stuff" with additional tables in the EPrints 
> database (primarily using them for records that are not part of the 
> EPrints application)
> 
> The basic idea is to extend EPrints::Database - as described in 
> http://stackoverflow.com/questions/14047407/extending-perl-module-from-within-the-calling-script
> 
> So, in an EPrints::DataObj::VisitorTickets package (which describes the 
> additional tables) I have
> 
> ===== start code ======
> use EPrints::Database;
> sub EPrints::Database::update_visitor_ticket
> {
> 	my( $self, $code, $user_id ) = @_;
> 	my $table = "visitorticket";
> 
> 	my $Q_table   = $self->quote_identifier( $table );
> 	my $Q_user_id = $self->quote_identifier( "userid" );
> 	my $Q_code    = $self->quote_identifier( "code" );
> 
> 	my $sql = "DELETE FROM $Q_table WHERE 
> $Q_userid=".$self->quote_int($userid)." AND 
> $Q_code=".$self->quote_value($code);
> 	$self->do($sql);
> 
> 	$self->insert( $table, ["code","userid","expires"], [
> 		$code,
> 		$userid,
> 		time()+3600
> 	]);
> 
> }
> ===== end code ======
> 
> and then in my script I have:
> 
> ===== start code =====
> $repo->{'database'}
>        ->update_visitor_ticket( $eprints_session, $secret_code, 
> $visitor_id );
> ===== end code =====
> 
> My problem is that, when I run the script that calls this, I get the error:
>    Can't locate object method "update_visitor_ticket" via package
>    "EPrints::Database::Pg"
> 
> Now - given that EPrints::Repository has the code
> ===== start code =====
> 	my $userid = $user->get_id;
> 	$self->{database}->update_ticket_userid( $code, $userid, $ip );
> ===== end code =====
> and works... I don't understand why EPrints::Repository works, and my 
> package doesn't...
> 
> Any ideas?
>