我有一个纯perl服务类PlainData,它从远程文件系统中检索一些普通数据。包含PlainData的包,它生成一些文本,以及一个状态标志(错误,警告)。我如何(把它,链接)到perl mason web上下文中。我会做这样的事情:
<%init>
use PlainData;
my $stn = $ARGS{"STN"};
my $yr = $ARGS{"YR"};
my $mo = $ARGS{"MO"};
my $dy = $ARGS{"DY"};
...do something with $stn,$yr,$mo,$dy,
my $plainDataHandler = new PlainData();
my ($status, $text) = $plainDtaHandler->listStationsByDay( $stn, $yr, $mo, $dy);
if ($status>10) {
print "<h1>ERROR REQUEST DATA STATIONS</h1>\n";
print $text;
} else {
print $text;
}
</%init>
我也尝试了
my $plainDataHandler = $m->comp('/var/perl/PlainData.pm');
答案 0 :(得分:0)
试
% if($status>10) {
<h1>ERROR REQUEST DATA STATIONS</h1>
% }
<% $text %>
% #some link
<a href="/some/url"><% $text %></a>
<%init>
...
my ($status, $text) = $plainDtaHandler->listStationsByDay( $stn, $yr, $mo, $dy);
</%init>