Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re: How to syntax-check Catalyst code which throws 'Invalid CODE attributes' errors?

by Your Mother (Archbishop)
on Jun 09, 2021 at 04:23 UTC ( [id://11133675]=note: print w/replies, xml ) Need Help??


in reply to How to syntax-check Catalyst code which throws 'Invalid CODE attributes' errors?

It’s not Moose, it’s specifically Catalyst’s handling of the information. Probably your Catalyst code is either wonky or relies on the presence of the base packages to already be loaded in such a way that sub packages will fail because they are missing dependent information. Compare these two–

perl -c -e 'sub taco :Chained("/") :PathPart("foo") : CaptureArgs(0) { +}' Invalid CODE attributes: Chained("/") : PathPart("foo") : CaptureArgs( +0) at -e line 1. BEGIN failed--compilation aborted at -e line 1.
perl -c -e 'use parent "Catalyst::Controller"; sub taco :Chained("/") +:PathPart("foo") : CaptureArgs(0) {}' -e syntax OK

Side-note about the -c flag. It’s not just a syntax check, it has to compile code and that means running some of it and there is no way to know what that might include without stepping through it. For example–

# emacs/vi UseMe.pm package UseMe; print STDERR "rm -rf /"; perl -c UseMe.pm UseMe.pm syntax OK perl -c -e 'use UseMe' rm -rf /-e syntax OK

Replies are listed 'Best First'.
Re^2: How to syntax-check Catalyst code which throws 'Invalid CODE attributes' errors?
by LittleJack (Beadle) on Jun 09, 2021 at 04:48 UTC

    That looks like exactly what I need, thank you. However I'm not quite understanding how I would use your inline example in my real-life situation, where I'm doing something like this:

    perl -I /some/path/perl5 -c Path/To/lib/Controller/Foo.pm

    How can I include your use parent code in that command?

      You can do that but I think you’re probably going to be happier testing the application itself instead of components; or testing the components from within the application. Controllers need to have a notion of the Catalyst context. Essentially, they don’t even properly exist except as part of a request dispatch. A controller endpoint cannot naturally do anything outside of that.

      What you’re doing is akin to trying to check subs inside a script instead of the script itself. It can be done but it’s weird given the, well, context of the code. Catalyst controllers aren’t code that can be run alone, only within and by the app. Side-note: models and views differ here. Catalyst only adds configuration and access affordances for those.

      Catalyst testing is really extremely good and flexible. Only Mojo is better, easier. It doesn’t require any (system, standalone, external) server or special environment or anything.

        I totally understand your point about not testing one file at a time but I'm in a tricky situation with source control which means I really need to to test things in isolation sometimes. I simply need to test for basic things like typos at one point in the lifecycle. So ... how would I do that?

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (7)
As of 2024-04-18 09:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found