Hi Dirk,
I think your question has less to do with CGI::Application than you think. Consider
this. Put the logic to your unix-admin into a
set of modules outside your web-application module:
instancescript.cgi
webapp.pm
AccountEditor::Unix.pm
AccountEditor::Solaris.pm ( 'ISA' AccountEditor::Unix )
AccountEditor::AIX.pm ( 'ISA' AccountEditor::Unix )
AccountEditor::HPUX.pm ( 'ISA' AccountEditor::Unix )
AccountEditor::FreeBSD.pm ( 'ISA' AccountEditor::Unix )
AccountEditor::Linux.pm ( 'ISA' AccountEditor::Unix )
You define all of the normal admin opertations in Unix.pm. You then selectively
add/override methods in the OS-specific modules.
Then if you've gotten their os preference in a variable called $osPref, you can do
something like this in your WebApp.pm:
sub setup {
my $self = shift;
$self->start_mode(...your default mode);
$self->mode_param(...your param here);
$self->run_modes( ... your run mode list here );
my %implementations = (
'Default' => 'AccountEditor::Unix',
'Solaris' => 'AccountEditor::Solaris',
...
);
my $implementation = $implementations{ $osPref } || $implementations{ 'Default' );
my $file = join('/', split(/::/, $implementation) ) . '.pm';
require $file;
$self->param('administrator', $implementation->new() );
}
Then in each run mode, you can check to see if the 'administrator' you've installed
can support the action that the run mode wants
to allow the user to do:
my $administrator = $self->param('administrator');
if( my $method = $administrator->can( 'action_for_this_runmode' ) ) {
$administrator->$method( parameters appropriate for the action );
return "success page";
}
else {
return "I'm Sorry, but I don't know how to do that"
}
HTH
-Stephen
-----Original Message-----
From: wessner [mailto:wessner]On Behalf Of Dirk Wessner
Sent: Thursday, March 14, 2002 07:56 PM
To: CGI::Application Mailing List
Subject: [cgiapp] OO Perl, Inheritance and so on
Hello.
Since I'm new both to CGI::Application and OO Perl it's not
easy to explain what I'd like to do.
For Example if I'd like to create a WebApp that manages
User accounts on different Unix Systems. There are run-modes
that will be the same for every Unix, others (sth. like "add_user" )
that are slightly different, and others that are totally different
or even additional because on a special host in addition to
create the user I want to put him into /etc/aliases and set quotas
and whatever.
As start-screen I would like to have a menue where you can choose
first the platform and then the host.
I read the perldoc for CGI::Application as well the O'Reilly
Article on www.perl.com.
Somehow you CAN do such a thing in an easy way, but I'm not
really sure exactly how to structure it.
Must have sth to do with the use of cgiapp_init() and the
possibility of calling run_modes() more than once.
OK, Building a "ordinary" WebApp using CGI::Application was
no problem for me, i.e. one instance script and one application
module with severeal run-modes in it.
But this is a bit different.
How exactly to inherit from a Superclass-WebApp?
Why does one use "use base 'CGI::Application';" and not
@ISA qw( CGI::Application ) , btw?
And what about a mechanism to decide what Class
exactly to instanciate at runtime? Different
instance-Scripts?
Hmm...I hope somebody understands my question(s).
Thanks in advance,
Dirk Wessner
---------------------------------------------------------------------
Web Archive: http://www.mail-archive.com/[email protected]/
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
---------------------------------------------------------------------
Web Archive: http://www.mail-archive.com/[email protected]/
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]