| 1 | #! /bin/false | ||||||||||
| 2 | |||||||||||
| 3 | # Copyright (C) 2016-2018 Guido Flohr <guido.flohr@cantanea.com>, | ||||||||||
| 4 | # all rights reserved. | ||||||||||
| 5 | |||||||||||
| 6 | # This program is free software: you can redistribute it and/or modify | ||||||||||
| 7 | # it under the terms of the GNU General Public License as published by | ||||||||||
| 8 | # the Free Software Foundation; either version 3 of the License, or | ||||||||||
| 9 | # (at your option) any later version. | ||||||||||
| 10 | |||||||||||
| 11 | # This program is distributed in the hope that it will be useful, | ||||||||||
| 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||||||||
| 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||||||||
| 14 | # GNU General Public License for more details. | ||||||||||
| 15 | |||||||||||
| 16 | # You should have received a copy of the GNU General Public License | ||||||||||
| 17 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | ||||||||||
| 18 | |||||||||||
| 19 | package Qgoda::Processor; | ||||||||||
| 20 | 3 | $Qgoda::Processor::VERSION = 'v0.9.2'; | |||||||||
| 21 | 3 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 22 | |||||||||||
| 23 | 3 | ▶ | use Locale::TextDomain qw(qgoda); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 24 | 3 | ▶ | use Scalar::Util qw(blessed); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 25 | 3 | ▶ | use URI; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 26 | 3 | ▶ | use URI::Escape qw(uri_unescape); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 27 | |||||||||||
| 28 | 3 | ▶ | use Qgoda; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 29 | 3 | ▶ | use Qgoda::Util qw(empty); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 30 | |||||||||||
| 31 | sub new { | ||||||||||
| 32 | 3 | ▶ | bless {}, shift; | ||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 33 | } | ||||||||||
| 34 | |||||||||||
| 35 | sub process { | ||||||||||
| 36 | 0 | ▶ | my ($self, $content, $asset) = @_; | ||||||||
|
Subroutine
process: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 37 | |||||||||||
| 38 | 0 | die __x("Processor class '{class}' does not implement the method process().\n", | |||||||||
| 39 | class => ref $self); | ||||||||||
| 40 | } | ||||||||||
| 41 | |||||||||||
| 42 | sub postMeta { | ||||||||||
| 43 | 5 | ▶ | my ($self, $content, $asset) = @_; | ||||||||
|
Subroutine
postMeta: called CC=7 SCAR=19.5
Pod
undocumented
| |||||||||||
| 44 | |||||||||||
| 45 | 5 | my $case_sensitive = Qgoda->new->config->{'case-senstive'}; | |||||||||
| 46 | |||||||||||
| 47 | 5 | require HTML::TreeBuilder; | |||||||||
| 48 | 5 | my $tree = HTML::TreeBuilder->new(implicit_body_p_tag => 1, | |||||||||
| 49 | ignore_ignorable_whitespace => 1); | ||||||||||
| 50 | 5 | $tree->parse($content); | |||||||||
| 51 | |||||||||||
| 52 | 5 | my @paragraphs = $tree->find('p', 'div'); | |||||||||
| 53 | 5 | my $excerpt = ''; | |||||||||
| 54 | 5 | foreach my $paragraph (@paragraphs) { | |||||||||
| 55 | 5 | $excerpt = $paragraph->as_text; | |||||||||
| 56 | 5 | $excerpt =~ s/^[ \t\r\n]+//; | |||||||||
| 57 | 5 | $excerpt =~ s/[ \t\r\n]+$//; | |||||||||
| 58 | 5 | ▶ | last if !empty $excerpt; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 59 | } | ||||||||||
| 60 | |||||||||||
| 61 | # Collect links. | ||||||||||
| 62 | 5 | my %links; | |||||||||
| 63 | 5 | foreach my $record (@{$tree->extract_links}) { | |||||||||
| 64 | 6 | my $href = uri_unescape $record->[0]; | |||||||||
| 65 | 6 | eval { | |||||||||
| 66 | 6 | my $canonical = URI->new($href)->canonical; | |||||||||
| 67 | 6 | $href = $canonical; | |||||||||
| 68 | }; | ||||||||||
| 69 | 6 | ▶ | if (!empty $href) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 70 | 6 | ▶ | if ('/' eq substr $href, 0, 1) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 71 | 2 | ▶ | $href = lc $href if !$case_sensitive; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 72 | } | ||||||||||
| 73 | |||||||||||
| 74 | # This will also count links to itself but they will be filtered | ||||||||||
| 75 | # out by Qgoda::Site->computeRelated(). | ||||||||||
| 76 | 6 | ++$links{$href}; | |||||||||
| 77 | } | ||||||||||
| 78 | } | ||||||||||
| 79 | |||||||||||
| 80 | 5 | return excerpt => $excerpt, links => [keys %links]; | |||||||||
| 81 | } | ||||||||||
| 82 | |||||||||||
| 83 | 3 | 1; | |||||||||
| 84 | |||||||||||
| 85 | =head1 NAME | ||||||||||
| 86 | |||||||||||
| 87 | Qgoda::Processor - Abstract base class for all Qgoda Processors. | ||||||||||