Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re: Best practices for warnings about wrong context

by Your Mother (Archbishop)
on Oct 05, 2015 at 12:38 UTC ( [id://1143804]=note: print w/replies, xml ) Need Help??


in reply to Best practices for warnings about wrong context

This Catalyst code is not sensible.

sub xxx : Local Args(0) { my ($self, $c, $s, $r, $p) = @_; $c->res->body( wantarray ); }

The arg handling is wrong Args(0) means just that, and there is no way using the return of wantarray could ever make sense as a body. If that is meant to be a stand-in for the void context function you speak about it should not be there but by itself.

sub xxx : Local Args(0) { my ($self, $c) = @_; function_in_void_context(); # And should be wrapped in model probably. # Naked function calls in Cat is code smell. $c->res->body("Value or none if falling back to template, etc"); }

Replies are listed 'Best First'.
Re^2: Best practices for warnings about wrong context
by vsespb (Chaplain) on Oct 05, 2015 at 16:39 UTC
    there is no way using the return of wantarray could ever make sense as a body
    Of course it makes sense. It prints "1" as body, means wantarray returns TRUE. This function is for PoC purpose.

      It does not. The body expects a string/scalar. $c->response->body(defined wantarray); prints "1". Maybe I am missing the point because a setter like ->body expects a value and is therefore never going to be a void context call; it's a strange question / concept to want to demonstrate.

        In this example wantarray returns context in which the action called, not related to what body expects, so
        $c->response->body(wantarray)
        same as
        my $x = wantarray; $c->response->body($x)

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1143804]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (6)
As of 2024-04-23 09:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found