how to reproduce:
a) mojo generate app
b) modify MyApp::Controller::Example like next:
package MyApp::Controller::Example;
use Mojo::Base 'Mojolicious::Controller';
This action will render a template
sub welcome {
my $self = shift;
Some::NameSpace::asdf;
Render template "example/welcome.html.ep" with message
$self->render(msg => 'Welcome to the Mojolicious real-time web framework!');
}
1;
c) fix templates/example/welcome.html.ep: s/$msg/stash->{msg}/
d) script/my_app daemon
e) Make two requests to 127.0.0.1:3000
Debug:
$ perl -d script/my_app daemon
[2019-06-07 18:28:00.83531] [17248] [info] Listening at "http://*:3000"
Server available at http://127.0.0.1:3000
[2019-06-07 18:28:44.52825] [17248] [debug] GET "/" (9a95b50d)
191: return 1 if $self->{loaded}{$app};
x192: if (my $e = loadclass $app) { ref $e ? die $e : return undef }
193:
194: # Check base classes
x195: return 0 unless first { $app->isa($) } @{$self->base_classes};
x196: return $self->{loaded}{$app} = 1;
197: }
198:
199: sub _render {
x200: my $c = shift;
x201: my $stash = $c->stash;
x202: return if $stash->{'mojo.rendered'};
x203: $c->render_maybe or $stash->{'mojo.routed'} or $c->helpers->reply->not_found;
204: }
205:
x206: 1;
207:
208: =encoding utf8
209:
210: =head1 NAME
211:
DBG>$self->{loaded}{$app}
undef
DBG>go
/home/kes/work/projects/tucha/monkeyman/local/lib/perl5/Mojo/Loader.pm
35: }
36:
37: sub load_class {
x38: my $class = shift;
39:
40: # Invalid class name
x41: return 1 if ($class || '') !~ /^\w(?:[\w:']*\w)?$/;
42:
x43: DB::x if $class eq 'MyApp::Controller::Example';
44: # Load if not already loaded
45: return undef if $class->can('new') || eval "require $class; 1";
46:
47: # Does not exist
x48: return 1 if $@ =~ /^Can't locate \Q@{[class_to_path $class]}\E in \@INC/;
49:
50: # Real error
x51: return Mojo::Exception->new($@)->inspect;
52: }
53:
54: sub _all {
x55: my $class = shift;
56:
x57: return $CACHE{$class} if $CACHE{$class};
x58: local $.;
x59: my $handle = do { no strict 'refs'; *{"${class}::DATA"} };
x60: return {} unless fileno $handle;
x61: seek $handle, 0, 0;
x62: my $data = join '', <$handle>;
63:
64: # Ignore everything before DATA (some versions seek to start of file)
x65: $data =~ s/^.*\nDATA\r?\n/\n/s;
DBG>$class->can('new')
undef
DBG>go
[2019-06-07 18:29:06.57785] [17248] [error] Bareword "Some::NameSpace::asdf" not allowed while "strict subs" in use at /home/kes/work/projects/del5/my_app/script/../lib/MyApp/Controller/Example.pm line 8, line 4.
Compilation failed in require at (eval 97)[/home/kes/work/projects/tucha/monkeyman/local/lib/perl5/Mojo/Loader.pm:45] line 1, line 4.
[2019-06-07 18:29:06.58124] [17248] [debug] Template "exception.development.html.ep" not found
[2019-06-07 18:29:06.58206] [17248] [debug] Template "exception.html.ep" not found
[2019-06-07 18:29:06.58285] [17248] [debug] Rendering template "mojo/debug.html.ep"
[2019-06-07 18:29:06.68189] [17248] [debug] 500 Internal Server Error (22.153597s, 0.045/s)
we see the error about bareword. Now we do second request:
[2019-06-07 18:30:03.10460] [17248] [debug] GET "/" (563571f0)
DBG>go
[2019-06-07 18:30:57.75624] [17248] [debug] Action not found in controller
[2019-06-07 18:30:57.75779] [17248] [debug] Rendering template "example/welcome.html.ep"
[2019-06-07 18:30:57.77188] [17248] [debug] Rendering template "layouts/default.html.ep"
[2019-06-07 18:30:57.77559] [17248] [debug] 200 OK (54.670832s, 0.018/s)
Now we see that no exception occur. One strange thing here is that 'MyApp::Controller::Example' becomes defined
thanks to tm604 he says: loading a module isn't transactional
should this condition take that into account?
https://github.com/mojolicious/mojo/blob/master/lib/Mojo/Loader.pm#L44
how to reproduce: a) mojo generate app b) modify MyApp::Controller::Example like next:
package MyApp::Controller::Example; use Mojo::Base 'Mojolicious::Controller';
This action will render a template
sub welcome { my $self = shift;
Some::NameSpace::asdf;
Render template "example/welcome.html.ep" with message
$self->render(msg => 'Welcome to the Mojolicious real-time web framework!'); }
1;
c) fix templates/example/welcome.html.ep: s/$msg/stash->{msg}/ d) script/my_app daemon e) Make two requests to 127.0.0.1:3000
Debug:
$ perl -d script/my_app daemon [2019-06-07 18:28:00.83531] [17248] [info] Listening at "http://*:3000" Server available at http://127.0.0.1:3000 [2019-06-07 18:28:44.52825] [17248] [debug] GET "/" (9a95b50d)
/home/kes/work/projects/tucha/monkeyman/local/lib/perl5/Mojolicious/Routes.pm 181: } 182: x183: return undef; 184: } 185: 186: sub load { x187: my ($self, $app) = @; 188: x189: DB::x if $app eq 'MyApp::Controller::Example'; 190: # Load unless already loaded
DBG>$self->{loaded}{$app} undef
DBG>go
/home/kes/work/projects/tucha/monkeyman/local/lib/perl5/Mojo/Loader.pm 35: } 36: 37: sub load_class { x38: my $class = shift; 39: 40: # Invalid class name x41: return 1 if ($class || '') !~ /^\w(?:[\w:']*\w)?$/; 42: x43: DB::x if $class eq 'MyApp::Controller::Example'; 44: # Load if not already loaded
DBG>$class->can('new') undef
DBG>go [2019-06-07 18:29:06.57785] [17248] [error] Bareword "Some::NameSpace::asdf" not allowed while "strict subs" in use at /home/kes/work/projects/del5/my_app/script/../lib/MyApp/Controller/Example.pm line 8, line 4.
Compilation failed in require at (eval 97)[/home/kes/work/projects/tucha/monkeyman/local/lib/perl5/Mojo/Loader.pm:45] line 1, line 4.
[2019-06-07 18:29:06.58124] [17248] [debug] Template "exception.development.html.ep" not found [2019-06-07 18:29:06.58206] [17248] [debug] Template "exception.html.ep" not found [2019-06-07 18:29:06.58285] [17248] [debug] Rendering template "mojo/debug.html.ep" [2019-06-07 18:29:06.68189] [17248] [debug] 500 Internal Server Error (22.153597s, 0.045/s)
we see the error about bareword. Now we do second request:
[2019-06-07 18:30:03.10460] [17248] [debug] GET "/" (563571f0)
/home/kes/work/projects/tucha/monkeyman/local/lib/perl5/Mojolicious/Routes.pm 181: } 182: x183: return undef; 184: } 185: 186: sub load { x187: my ($self, $app) = @; 188: x189: DB::x if $app eq 'MyApp::Controller::Example'; 190: # Load unless already loaded
DBG>$self->{loaded}{$app} undef
DBG>go
/home/kes/work/projects/tucha/monkeyman/local/lib/perl5/Mojo/Loader.pm 35: } 36: 37: sub load_class { x38: my $class = shift; 39: 40: # Invalid class name x41: return 1 if ($class || '') !~ /^\w(?:[\w:']*\w)?$/; 42: x43: DB::x if $class eq 'MyApp::Controller::Example'; 44: # Load if not already loaded
DBG>$class->can('new') &Mojolicious::Controller::_Base::new
DBG>go [2019-06-07 18:30:57.75624] [17248] [debug] Action not found in controller [2019-06-07 18:30:57.75779] [17248] [debug] Rendering template "example/welcome.html.ep" [2019-06-07 18:30:57.77188] [17248] [debug] Rendering template "layouts/default.html.ep" [2019-06-07 18:30:57.77559] [17248] [debug] 200 OK (54.670832s, 0.018/s)
Now we see that no exception occur. One strange thing here is that 'MyApp::Controller::Example' becomes defined