On Sun, 18 Dec 2005, Rhesa Rozendaal <[EMAIL PROTECTED]> wrote:
Here's a sketch of my app structure as it is now. I show two parts, the
main, formerly monolithic CgiApp, and one package with a set of run
modes.
package My::MainApp;
use base qw/My::BaseApp/; # I already have this one; it handles sessions etc
use My::MainApp::Admin; # contains the run modes dealing with admin functions
use My::MainApp::News; # another example package of run modes
# rest of app follows
# this app still has some runmodes of its own, but most have been moved
# into the packages use()d above.
1;
package My::MainApp::Admin;
use CGI::Application; # to get the callback functionality
use base qw/Exporter/;
sub import
{
caller()->add_callback( 'prerun' => sub {
my $self = shift;
$self->run_modes([qw/
save_user
delete_user
/]);
} );
goto &Exporter::import;
}
sub save_user {} # these used to be a run mode in MainApp
sub delete_user {} # but are now in their own package
1;
Hope that helps a bit :)
Thanks Rhesa, I'm sure it will help when I can get it working. I have
taken some run-modes out of the main app into a new module called
NewPatient, declared the package NewPatient in NewPatient.pm, with the
new import() method listing an arrayref of re-located run-modes, use'ing
CGI::Application and base 'Exporter', and referenced the new module in
the main app with 'use NewPatient'. So far so good. But now when I
invoke my application it says 'Error executing run mode 'new_patient':
Can't locate object method "new_patient" via package "MyApp" at
c:/usr/local/site/lib/CGI/Application.pm line 154", (yes it's a Win32
setup!), where MyApp is the main application invoked by the instance
script.
But the new_patient method *is* there and is also referenced in the
$self->run_modes arrayref. I know the app is finding the package
NewPatient because if I comment out the line 'use NewPatient' in MyApp
the AUTOLOAD => \&_exception runmode gets called.
I'm not at all familiar with the add_callback() and caller() functions
of import(), and I don't think I've ever used the 'prerun' function
before. Perhaps I've missed an important step somewhere?
--
Richard Jones
Leeds, UK
mailto:[EMAIL PROTECTED]
---------------------------------------------------------------------
Web Archive: http://www.mail-archive.com/[email protected]/
http://marc.theaimsgroup.com/?l=cgiapp&r=1&w=2
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]