加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

Perl Mason语法验证

发布时间:2020-12-15 23:20:57 所属栏目:大数据 来源:网络整理
导读:有没有办法在命令行验证perl mason语法?我知道对于常规的perl模块你可以使用perl -c,但是这会抛出像docstrings之类的特定于mason的语法的错误…… 例如: %docDOCUMENTATION SHOULD NOT GET PARSED/%doc%args$args/%args%perlmy $var = $args-{var};/%perl
有没有办法在命令行验证perl mason语法?我知道对于常规的perl模块你可以使用perl -c,但是这会抛出像docstrings之类的特定于mason的语法的错误……

例如:

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

<%args>
$args
</%args>

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

是一个有效的perl mason文件,但对它运行perl -c会返回:

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.

解决方法

我看了一下梅森,我看到的第一件事就是 Mason::App/ mason.pl

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

整洁吧?但这实际上是试图运行代码,所以下一步是看看里面,稍微环顾四周后,我发现Mason::Interp有load (path),记录为

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.

所以你可以调整Mason :: App来加载而不是运行或制作你自己的简单版本

#!/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 );

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读