我有一个纯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');
try
% 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>