EPrints Technical Mailing List Archive
Message: #00354
< Previous (by date) | Next (by date) > | < Previous (in thread) | Next (in thread) > | Messages - Most Recent First | Threads - Most Recent First
[EP-tech] Re: Altering DajaObj/Eprint.pm behaviour without altering core code
- To: "'eprints-tech@ecs.soton.ac.uk'" <eprints-tech@ecs.soton.ac.uk>
- Subject: [EP-tech] Re: Altering DajaObj/Eprint.pm behaviour without altering core code
- From: John Salter <J.Salter@leeds.ac.uk>
- Date: Wed, 4 Apr 2012 16:44:17 +0100
For render_fileinfo Tim's suggestion would be OK, but what about non-rendering methods - like 'remove'? Currently in a modified ~/perl_lib/EPrints/DataObj/Eprint.pm, I have: sub remove { ... #JLRS Added code my $repo = $self->{session}->get_repository->get_id; if( $repo eq "sherpawhiterose" ){ # some stuff that's only applicable to 'sherpawhiterose' ... } #/JLRS Added code return $success; } Ideally this would be done somewhere in ~/archives/sherpawhiterose/cfg/, and not affect any other archives. Could I wrap a set of rules with some kind of archive-specific selector: [in this archive] *EPrints::DataObj::EPrint::remove = \&patched_DataObj_EPrint_remove; *EPrints::DataObj::EPrint::move_to_archive = \&patched_DataObj_EPrint_move_to_archive; [/in this archive] Cheers, John -----Original Message----- From: eprints-tech-bounces@ecs.soton.ac.uk [mailto:eprints-tech-bounces@ecs.soton.ac.uk] On Behalf Of Sebastien Francois Sent: 04 April 2012 16:05 To: eprints-tech@ecs.soton.ac.uk Subject: [EP-tech] Re: Altering DajaObj/Eprint.pm behaviour without altering core code On 04/04/12 15:49, John Salter wrote: > I really meant to suggest making the change in ~/archives/[ID]/cfg/cfg.d/core_overrides.pl > - would a change in there result in this inheritance? I think it would since EPrints::DataObj::EPrint.pm is loaded once by the webserver and you're changing it. What about Tim Brody's suggestion? That would be rather clean. Alternatively, try something like that: *EPrints::DataObj::EPrint::render_fileinfo = \&patched_render_fileinfo; sub patched_render_fileinfo { my( $session, $field, $value, $alllangs, $nolink, $eprint ) = @_; if( $session->can_call( 'local_render_fileinfo' ) ) { return $session->call( 'local_render_fileinfo', $session, $field, $value, $alllangs, $nolink, $eprint ); } # original render_fileinfo code follows: # ... } $c->{local_render_fileinfo} = sub { # your custom code }; If you don't define $c->{local_render_fileinfo} in your other repositories, then the original code will be executed. Seb. > I need to make the change in one archive only! > > Cheers, > John > > -----Original Message----- > From: eprints-tech-bounces@ecs.soton.ac.uk [mailto:eprints-tech-bounces@ecs.soton.ac.uk] On Behalf Of Sebastien Francois > Sent: 04 April 2012 15:41 > To: eprints-tech@ecs.soton.ac.uk > Subject: [EP-tech] Re: Altering DajaObj/Eprint.pm behaviour without altering core code > > Good! Yes I'd add a file in cfg.d/ as you suggested. However be aware > that other repositories set up there (ie. archives/[id1], > archives/[id2]...) will inherit the change! > > Seb. > > On 04/04/12 15:33, John Salter wrote: >> Thanks Seb, works like a dream! >> >> Do you have any 'good practice' advice on how to do this within an archive? >> I already have ~/archives/[ID]/cfg/plugins/... for over-riding plugins. >> Would your advice be to add something within there, or to add something like cfg.d/core_overrides.pl? >> >> Cheers, >> John >> >> -----Original Message----- >> From: eprints-tech-bounces@ecs.soton.ac.uk [mailto:eprints-tech-bounces@ecs.soton.ac.uk] On Behalf Of Sebastien Francois >> Sent: 04 April 2012 12:29 >> To: eprints-tech@ecs.soton.ac.uk >> Subject: [EP-tech] Re: Altering DajaObj/Eprint.pm behaviour without altering core code >> >> What about: >> >> *EPrints::DataObj::EPrint::render_fileinfo = \&my_render_fileinfo; >> >> sub my_render_fileinfo >> { >> # your code ... >> } >> >> Seb. >> >> >> On 04/04/12 12:18, John Salter wrote: >>> I'm trying to do something the 'right way'*. >>> This advice: http://wiki.eprints.org/w/Read_Only_Directories says I shouldn't be editing anything under eprints3/perl_lib/ (with a couple of exceptions). >>> >>> I need to alter the 'render_fileinfo' subroutine in ~/perl_lib/EPrints/DataObj/EPrint.pm. >>> How do I achieve this without: >>> - altering the Eprint.pm file >>> - ending up with some 'Subroutine render_fileinfo redefined' messages >>> - using "no warnings 'redefine';" ;o) >>> >>> I've tried various attempts - without success. >>> I'm sure it can be done, and I'm sure it's a bit of perl magic I'm missing, and hopefully someone here can help! >>> >>> Cheers, >>> John >>> >>> *http://blogs.ecs.soton.ac.uk/oneshare/2009/09/25/taking-stock-and-mopping-up-the-mess-i-made-of-eprints/ >>> *** Options: http://mailman.ecs.soton.ac.uk/mailman/listinfo/eprints-tech >>> *** Archive: http://www.eprints.org/tech.php/ >>> *** EPrints community wiki: http://wiki.eprints.org/ >> *** Options: http://mailman.ecs.soton.ac.uk/mailman/listinfo/eprints-tech >> *** Archive: http://www.eprints.org/tech.php/ >> *** EPrints community wiki: http://wiki.eprints.org/ >> >> *** Options: http://mailman.ecs.soton.ac.uk/mailman/listinfo/eprints-tech >> *** Archive: http://www.eprints.org/tech.php/ >> *** EPrints community wiki: http://wiki.eprints.org/ > *** Options: http://mailman.ecs.soton.ac.uk/mailman/listinfo/eprints-tech > *** Archive: http://www.eprints.org/tech.php/ > *** EPrints community wiki: http://wiki.eprints.org/ > > *** Options: http://mailman.ecs.soton.ac.uk/mailman/listinfo/eprints-tech > *** Archive: http://www.eprints.org/tech.php/ > *** EPrints community wiki: http://wiki.eprints.org/ *** Options: http://mailman.ecs.soton.ac.uk/mailman/listinfo/eprints-tech *** Archive: http://www.eprints.org/tech.php/ *** EPrints community wiki: http://wiki.eprints.org/
- Follow-Ups:
- [EP-tech] Re: Altering DajaObj/Eprint.pm behaviour without altering core code
- From: Tim Brody <tdb2@ecs.soton.ac.uk>
- [EP-tech] Re: Altering DajaObj/Eprint.pm behaviour without altering core code
- From: Sebastien Francois <sf2@ecs.soton.ac.uk>
- [EP-tech] Re: Altering DajaObj/Eprint.pm behaviour without altering core code
- References:
- [EP-tech] Altering DajaObj/Eprint.pm behaviour without altering core code
- From: John Salter <J.Salter@leeds.ac.uk>
- [EP-tech] Re: Altering DajaObj/Eprint.pm behaviour without altering core code
- From: Sebastien Francois <sf2@ecs.soton.ac.uk>
- [EP-tech] Re: Altering DajaObj/Eprint.pm behaviour without altering core code
- From: John Salter <J.Salter@leeds.ac.uk>
- [EP-tech] Re: Altering DajaObj/Eprint.pm behaviour without altering core code
- From: Sebastien Francois <sf2@ecs.soton.ac.uk>
- [EP-tech] Re: Altering DajaObj/Eprint.pm behaviour without altering core code
- From: John Salter <J.Salter@leeds.ac.uk>
- [EP-tech] Re: Altering DajaObj/Eprint.pm behaviour without altering core code
- From: Sebastien Francois <sf2@ecs.soton.ac.uk>
- [EP-tech] Altering DajaObj/Eprint.pm behaviour without altering core code
- Prev by Date: [EP-tech] Re: Altering DajaObj/Eprint.pm behaviour without altering core code
- Next by Date: [EP-tech] Re: XAPIAN Search
- Previous by thread: [EP-tech] Re: Altering DajaObj/Eprint.pm behaviour without altering core code
- Next by thread: [EP-tech] Re: Altering DajaObj/Eprint.pm behaviour without altering core code
- Index(es):