File Coverage

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

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