Carl Franks
2005-08-15 21:49:13 UTC
I find that if I try to change the current page, by returning a
different value from 'respond', it dies with "initialize_CGI not
called".
I think this is because when the new page's package is required, it
reruns the code in CGI/Prototype.pm which add's the 'dummy' CGI slot
which dies with that exact error message.
(I thought that a module's body was only run once, for the first 'use'
or 'require', but I can't see any other explanation for what's
happening).
Am I doing this correctly?
Should I file a bug report on rt?
(Sample code below).
Cheers,
Carl
# file One.pm
package One;
use warnings;
use strict;
use base 'CGI::Prototype';
sub respond {
require Two;
return 'Two';
}
1;
# file Two.pm
package Two;
use warnings;
use strict;
use base 'CGI::Prototype';
sub template {
return \'[% self.CGI.header %]Two';
}
1;
# file test.t
#!/usr/bin/perl
use strict;
use warnings;
use CGI::Prototype::Mecha;
use Test::More tests => 2;
use Data::Dumper;
use lib '.';
my $t = CGI::Prototype::Mech->new( protoapp => 'One' );
$t->get( 'http://mecha/' );
ok $t->success;
ok $t->res =~ 'Two';
print STDERR Dumper $t->res;
different value from 'respond', it dies with "initialize_CGI not
called".
I think this is because when the new page's package is required, it
reruns the code in CGI/Prototype.pm which add's the 'dummy' CGI slot
which dies with that exact error message.
(I thought that a module's body was only run once, for the first 'use'
or 'require', but I can't see any other explanation for what's
happening).
Am I doing this correctly?
Should I file a bug report on rt?
(Sample code below).
Cheers,
Carl
# file One.pm
package One;
use warnings;
use strict;
use base 'CGI::Prototype';
sub respond {
require Two;
return 'Two';
}
1;
# file Two.pm
package Two;
use warnings;
use strict;
use base 'CGI::Prototype';
sub template {
return \'[% self.CGI.header %]Two';
}
1;
# file test.t
#!/usr/bin/perl
use strict;
use warnings;
use CGI::Prototype::Mecha;
use Test::More tests => 2;
use Data::Dumper;
use lib '.';
my $t = CGI::Prototype::Mech->new( protoapp => 'One' );
$t->get( 'http://mecha/' );
ok $t->success;
ok $t->res =~ 'Two';
print STDERR Dumper $t->res;