Egad I have been a lazy Sod
Yep been a while since I posted something, been playing about with my HAM gear too much these days, but I do have a little gem of wisdom to share so here it is.
I updated my Mojolicious for the first time in quite awhile and my personal web server died.
Well this on was 100% my fault as the error was
Can't locate object method "route" via package "Mojolicious::Routes" at /johns/perl/Mojolicious-Plugin-Routes-Restful-0.03-2/blib/lib/Mojolicious/Plugin/Routes/Restful.pm line 124.
So I had a snoop around Mojolicious today and found this in the change log
8.67 2020-12-04 - Deprecated Mojolicious::Routes::Route::route in favor of Mojolicious::Routes::Route::any. - Deprecated Mojolicious::Routes::Route::over in favor of Mojolicious::Routes::Route::requires. - Deprecated Mojolicious::Routes::Route::via in favor of Mojolicious::Routes::Route::methods.
Ok and then a little higher in the file
9.0 2021-02-14 … Removed deprecated detour, over, route and via methods from Mojolicious::Routes::Route.
Ok so there is my problem. A few minutes of re-learning how to use github than a quick swap of 'route' for 'any' and ' via' for 'methods' and I though I was all done
I ran the test suite andt/10-basic-routes.t ..... ok t/20-basic-rest.t ....... ok t/30-advanced-routes.t .. ok Mojo::Reactor::Poll: I/O watcher failed: A response has already been rendered at /opt/cgt/milk/local/lib/perl5/Mojolicious/Controller.pm line 154. # Premature connection close t/40-advanced-rest.t .. 16/? # Failed test 'GET /V_1/myapp/project/1/view_users/1' # at t/40-advanced-rest.t line 102. # Failed test '200 OK' # at t/40-advanced-rest.t line 102. # got: undef # expected: '200' # Looks like you failed 2 tests of 17. t/40-advanced-rest.t .. Dubious, test returned 2 (wstat 512, 0x200) Failed 2/17 subtests
Ok where did that come from??
Well a good few hours later as I exhausted all my google searches, I had traced the croak back to this line
croak 'A response has already been rendered' if $c->stash->{'mojo.respond'}++;
In Mojolicious::Renderer;
Being the ham-fisted programmer that I am I took out that offending line from my core perl, as I could find 'mojo.respond' nowhere else in the code and of course this was the result
t/40-advanced-rest.t .... ok
Oh goody a bug to report!!
I as I was busily writing up a bug report, happy in thinking that at least one of my problems for today was not my fault I had a little brainstorm just before I hit 'submit' and I wanted to know who to 'blame' for this obvious bug
Ok Sebastian is at fault, good!
However my better judgment kicked in, funny as never does that usually, and I decided to have a look at the diff for this change and I found the note
Throw an exception if double rendering is attempted
now that got me thinking and I had a look at the innards of my test and found this
sub get {
my $self = shift;
if ( $self->req->method eq 'GET' ) {
$self->render( json => { status => 200 } );
}
$self->render( json => { status => 404 } );
}
opps I am doing a double render d'ho
So one 'else ' fixes that
if ( $self->req->method eq 'GET' ) {
$self->render( json => { status => 200 } );
}
else {
$self->render( json => { status => 404 } );
}
and after I had done this fix in a few spots, and put my core perl back to the orginial code I was getting
t/40-advanced-rest.t .... ok
Boy I am glad I did not hit submit on that bug report.
So if you run into that croak message
Mojo::Reactor::Poll: I/O watcher failed: A response has already been rendered at /opt/cgt/milk/local/lib/perl5/Mojolicious/Controller.pm
Check you code as it is not Mojolicious doing you wrong.
Leave a comment