[cgiapp] Can I override CAP::Dispatch::dispatch_path() ?
silent
silent2600 at gmail.com
Mon Mar 23 03:33:18 EDT 2009
just:
#!perl
use Mydispatch;
Mydispatch->dispatch();
and I write a simple one:
/MyApp# more Base.pm Foo.pm Bar.pm Dispatch.pm ../myapp.fcgi
::::::::::::::
Base.pm
::::::::::::::
package MyApp::Base;
use base 'CGI::Application::FastCGI';
1;
::::::::::::::
Foo.pm
::::::::::::::
package MyApp::Foo;
use base 'MyApp::Base';
sub setup {
my $self = shift;
$self->mode_param(
param => 'rm',
path_info => '1',
);
$self->start_mode('foo1');
$self->run_modes(
'foo1' => 'foo1',
'foo2' => 'foo2',
);
}
sub foo1 {
my $self = shift;
return "this is foo 1";
}
sub foo2 {
my $self = shift;
return "this is foo 2";
}
1;
::::::::::::::
Bar.pm
::::::::::::::
package MyApp::Bar;
use base 'MyApp::Base';
sub setup {
my $self = shift;
$self->mode_param(
param => 'rm',
path_info => '1',
);
$self->start_mode('bar1');
$self->run_modes(
'bar1' => 'bar1',
'bar2' => 'bar2',
);
}
sub bar1 {
my $self = shift;
return "this is bar 1";
}
sub bar2 {
my $self = shift;
return "this is bar 2";
}
1;
::::::::::::::
Dispatch.pm
::::::::::::::
package MyApp::Dispatch;
use base 'CGI::Application::Dispatch';
sub dispatch_path {
my $uri = $ENV{'REQUEST_URI'};
my $name = $ENV{'SCRIPT_NAME'};
$uri =~s/^$name//;
$uri =~s/\?.*$//;
$ENV{'PATH_INFO'} = $uri;
warn "[+] $uri\n";
return $uri;
}
sub dispatch_args {
return {
prefix => 'MyApp',
table => [
'' => { app => 'Foo' },
':app/:rm' => {},
],
};
}
1;
::::::::::::::
../myapp.fcgi
::::::::::::::
#!/usr/bin/perl
use lib "/var/www/fcgi/myapp";
use MyApp::Dispatch;
MyApp::Dispatch->dispatch();
### nginx config:
location /myapp {
fastcgi_pass unix:/tmp/fcgi.sock;
include fastcgi_params;
fastcgi_param SCRIPT_NAME "/myapp";
}
### start the fastcgi script with lighttpd's spawn-fcgi
spawn-fcgi -u www-data -g www-data -c / -s /tmp/fcgi.sock -f
/path/to/myapp.fcgi -n
2009/3/21 Michael Peters <mpeters at plusthree.com>:
> silent wrote:
>
>> but it seems not work, all the request goto the default app default
>> run_mode.
>
> You don't show where you're using Mydispatch or how your using it.
>
> --
> Michael Peters
> Plus Three, LP
>
More information about the cgiapp
mailing list