#!/usr/local/bin/perl
# http://www.nikkei.co.jp/ からトピックスの一文を抜き出して表示するサンプル
# http://www.hatena.ne.jp/1113230740

use strict;
use LWP::Simple;
use Template::Extract;
use Jcode;

my $uri = 'http://www.nikkei.co.jp';
my $document = jcode(LWP::Simple::get($uri))->sjis;

my $template = <<'EOD';
<h1 id="headline"><a href="[% url %]" name="topnews" accesskey="o">
<!--FJZONE START NAME="MIDASHI" -->
[% title %]
<!--FJZONE END NAME="MIDASHI" -->
</a></h1>
<p>
<!--FJZONE START NAME="HONBUN" -->
[% abstract %]
<!--FJZONE END NAME="HONBUN" -->
EOD

my $obj = Template::Extract->new;
my $ext = $obj->extract($template, $document);

print <<"EOD";
Content-Type: text/html

<h1>$ext->{title}</h1>
<p>$ext->{abstract} (<a href="$uri$ext->{url}">全文</a>)</p>
EOD
