I have been trying to use this module with a CGIApp that connects to a database. It works well from the browser, but when using it from your module, I get two different errors. If I initialize the app this way:
my $custom_mech = Test::WWW::Mechanize::CGIApp->new;
$custom_mech->app(
sub {
require "My::WebApp";
my $app = My::WebApp->new();
$app->fiddle_with_stuff();
$app->run();
});
The database handle seems to dissapear when actually calling the run mode. And I I create it in the usual way, via a class that initializes itself,
$mech->app( " Net::Lujoyglamour::WebApp::Test" );
When I arrive to this code in CGIApp: if (defined ($app)) {
if (ref $app) {
if (ref $app eq 'CODE') {
&{$app};
}
else {
die "The app value is a ref to something that isn't implemented.";
}
}
else {
# use eval since the module name isn't a BAREWORD
eval "require " . $app;
if ($app->isa("CGI::Application::Dispatch")) {
$app->dispatch();
}
elsif ($app->isa("CGI::Application")) {
my $app = $app->new();
$app->run();
}
else {
die "Unable to use the value of app.";
}
}
I obviously get an error indicating that you can't do an ->isa on a string. This seems an obvious bug, you are require'ing a string (a module name) and then you're using it as an object... The module above inherits indirectly from CGI::Application, not directly.
Cheers
JJ
my $custom_mech = Test::WWW::Mechanize::CGIApp->new;
$custom_mech->app(
sub {
require "My::WebApp";
my $app = My::WebApp->new();
$app->fiddle_with_stuff();
$app->run();
});
The database handle seems to dissapear when actually calling the run mode. And I I create it in the usual way, via a class that initializes itself,
$mech->app( " Net::Lujoyglamour::WebApp::Test" );
When I arrive to this code in CGIApp: if (defined ($app)) {
if (ref $app) {
if (ref $app eq 'CODE') {
&{$app};
}
else {
die "The app value is a ref to something that isn't implemented.";
}
}
else {
# use eval since the module name isn't a BAREWORD
eval "require " . $app;
if ($app->isa("CGI::Application::Dispatch")) {
$app->dispatch();
}
elsif ($app->isa("CGI::Application")) {
my $app = $app->new();
$app->run();
}
else {
die "Unable to use the value of app.";
}
}
I obviously get an error indicating that you can't do an ->isa on a string. This seems an obvious bug, you are require'ing a string (a module name) and then you're using it as an object... The module above inherits indirectly from CGI::Application, not directly.
Cheers
JJ