|< 1 2 3 >| | 29 Einträge, 3 Seiten |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
package MyApp::Login::Form;
sub new
{
...
}
...
1;
package MyApp;
use base 'CGI::Application';
sub setup
{
my $self = shift;
$self->header_props(
-type => 'text/html',
-charset => 'utf-8',
);
$self->mode_param('action');
$self->start_mode('login::form');
$self->run_modes(
'login::form' => ? ? ?,
);
}
1;
1
2
3
$self->run_modes(
'login::form' => sub { require MyApp::Login::Form; MyApp::Login::Form->new()->run() }
);
1 2 3 4 5 6 7 8 9 10 11 12 13 14
package XYZ::Config; use warnings; use strict; use vars qw(%Config); %Config = ( start => { action => \&XYZ::Action::Start, template => 'start.tmpl', }, list => { action => \&XYZ::Action::List, template => 'list.tmpl', }, # ... );
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
#! /usr/bin/perl use warnings; use strict; use CGI; use CGI::Carp qw(fatalsToBrowser warningsToBroser); my $cgi = CGI->new(); my $action = $cgi->param('action') || 'start'; if (exists $XYZ::Config::Config{$action} and ref($XYZ::Config::Config{$action}->{action}) ) { $XYZ::Config::Config{$action}->{action}->($cgi, $action, ...); } # if else { # fallback $XYZ::Config::Config{'start'}->{action}->($cgi, 'start', ...); } # else
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
package MyApp;
use Catalyst;
MyApp->action(
_end => sub {
my ( $self, $c ) = @_;
$c->forward('MyApp::View::TT') unless $c->response->output;
},
'index.html' => sub {
my ( $self, $c ) = @_;
$c->stash->{template} = 'index.tt';
},
'hello.html' => sub {
my ( $self, $c ) = @_;
$c->response->output('Hello Catalyst');
},
'/^product[_]*(\d*).html$/' => sub {
my ( $self, $c ) = @_;
$c->stash->{template} = 'product.tt';
$c->stash->{product} = $c->req->snippets->[0];
}
);
1;
perl -MCatalyst::Test=MyApp -e1 product_23.html
|< 1 2 3 >| | 29 Einträge, 3 Seiten |