File Coverage

File:lib/SEO/Inspector/Plugin/TitleCheck.pm
Coverage:90.9%

linestmtbrancondsubtimecode
1package SEO::Inspector::Plugin::TitleCheck;
2
3
5
5
5
1370
7
87
use strict;
4
5
5
5
9
4
88
use warnings;
5
5
5
5
9
3
10
use HTML::TreeBuilder;
6
7
7
31
sub new { bless {}, shift }
8
9
0
0
sub name { 'TitleCheck' }
10
11sub run {
12
5
5
    my ($self, $html) = @_;
13
14
5
13
    my $tree = HTML::TreeBuilder->new;
15
5
540
    $tree->parse_content($html);
16
17    # Find the <title> element safely
18
5
1752
    my $title;
19
5
10
    for my $el ($tree->find_by_tag_name('title')) {
20
4
122
        $title = $el->as_text;
21
4
42
        last;
22    }
23
24
5
32
    $tree->delete;
25
26
5
182
    if ($title && length $title) {
27
4
35
        return { status => 'ok', notes => 'title present' };
28    }
29
30
1
5
    return { status => 'error', notes => 'missing title' };
31}
32
331;