Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Perl Mason Syntax Validation

Is there a way to validate perl mason syntax at the command line? I know for regular perl modules you can just use perl -c, but that throws errors for mason-specific syntax like docstrings and the like...

For example:

<%doc>
DOCUMENTATION SHOULD NOT GET PARSED
</%doc>

<%args>
$args
</%args>

<%perl>
my $var = $args->{var};
</%perl>

is a valid perl mason file, but running perl -c against it returns:

Semicolon seems to be missing at path/to/file.mc line 1.
syntax error at path/to/file.mc line 2, near "DOCUMENTATION S"
path/to/file.mc had compilation errors.
like image 659
therealmitchconnors Avatar asked Dec 26 '22 00:12

therealmitchconnors


1 Answers

I took a look at Mason, the first thing I see is Mason::App/mason.pl

$ mason junk.mason
Invalid attribute line '$args' at ./junk.mason line 6

Neat huh? But that actually tries to run the code, so next step is look inside, and after a little looking around, i find Mason::Interp which has load (path) which is documented as

Returns the component object corresponding to an absolute component path, or undef if none exists. Dies with an error if the component fails to load because of a syntax error.

So you can adapt Mason::App to load instead of run or make your own simple version like this

#!/usr/bin/perl --
use strict; use warnings; use Mason;
my $interp = Mason->new(
    comp_root => '/path/to/comps',
    data_dir  => '/path/to/data',
    ...
);
$interp->load( shift );
like image 163
optional Avatar answered Feb 20 '23 07:02

optional