#! /bin/false
$Qgoda::Processor::VERSION
=
'0.9.8'
;
sub
new {
bless
{},
shift
;
}
sub
process {
my
(
$self
,
$content
,
$asset
) =
@_
;
die
__x(
"Processor class '{class}' does not implement the method process().\n"
,
class
=>
ref
$self
);
}
sub
postMeta {
my
(
$self
,
$content
,
$asset
) =
@_
;
my
$case_sensitive
= Qgoda->new->config->{
'case-senstive'
};
my
$tree
= HTML::TreeBuilder->new(
implicit_body_p_tag
=> 1,
ignore_ignorable_whitespace
=> 1);
$tree
->parse(
$content
);
my
@paragraphs
=
$tree
->find(
'p'
,
'div'
);
my
$excerpt
=
''
;
foreach
my
$paragraph
(
@paragraphs
) {
$excerpt
=
$paragraph
->as_text;
$excerpt
=~ s/^[ \t\r\n]+//;
$excerpt
=~ s/[ \t\r\n]+$//;
last
if
!empty
$excerpt
;
}
my
%links
;
foreach
my
$record
(@{
$tree
->extract_links}) {
my
$href
= uri_unescape
$record
->[0];
eval
{
my
$canonical
= URI->new(
$href
)->canonical;
$href
=
$canonical
;
};
if
(!empty
$href
) {
if
(
'/'
eq
substr
$href
, 0, 1) {
$href
=
lc
$href
if
!
$case_sensitive
;
}
++
$links
{
$href
};
}
}
return
excerpt
=>
$excerpt
,
links
=> [
keys
%links
];
}
1;
=head1 NAME
Qgoda::Processor - Abstract base class
for
all Qgoda Processors.