From 392d0cbdb596fe4fd645bed33cd564a5a3d6026f Mon Sep 17 00:00:00 2001 From: fukachan Date: Wed, 28 Feb 2001 14:09:16 +0000 Subject: dynamic load $ticket_model --- fml/lib/FML/CGI/TicketSystem.pm | 55 +++++++++++++++++++++++++++++++++-------- 1 file changed, 45 insertions(+), 10 deletions(-) (limited to 'fml') diff --git a/fml/lib/FML/CGI/TicketSystem.pm b/fml/lib/FML/CGI/TicketSystem.pm index 3ea72889..9e17b847 100644 --- a/fml/lib/FML/CGI/TicketSystem.pm +++ b/fml/lib/FML/CGI/TicketSystem.pm @@ -12,6 +12,11 @@ package FML::CGI::TicketSystem; use strict; use vars qw(@ISA @EXPORT @EXPORT_OK $AUTOLOAD); use Carp; +use CGI qw/:standard/; # load standard CGI routines +use FML::Process::CGI; + +@ISA = qw(FML::Process::CGI Exporter); + =head1 NAME @@ -33,33 +38,63 @@ C is a subclass of C. =head1 METHODS -=cut - -use CGI qw/:standard/; # load standard CGI routines -use FML::Process::CGI; - -@ISA = qw(FML::Process::CGI Exporter); - +Almost methods are forwarded to C base class. =head2 C +main method. + =cut # See CGI.pm for more details sub run { - my ($curproc) = @_; + my ($curproc, $args) = @_; + my $ticket = $curproc->_load_ticket_model_module($args); + + print start_html('ticket system interface'), "\n"; - print start_html('hello world'), "\n"; print "
\n";
-    print " hen hen hen \n";
+
+    my $argv     = $args->{ ARGV };
+    $argv->[ 0 ] = 'list';
+    $ticket->show_summary($curproc, $args);
+
     print "
\n"; + + print "\n"; print end_html; print "\n"; } +sub _load_ticket_model_module +{ + my ($curproc, $args) = @_; + my $config = $curproc->{ config }; + my $model = $config->{ ticket_model }; + my $pkg = "FML::Ticket::Model::"; + + if ($model eq 'toymodel') { + $pkg .= $model; + } + else { + Log("ticket: unknown model"); + return; + } + + # fake use() to do "use FML::Ticket::$model;" + eval qq{ require $pkg; $pkg->import();}; + unless ($@) { + return $pkg->new($curproc, $args); + } + else { + Log($@); + } +} + + =head1 SEE ALSO L, -- cgit v1.2.1