File Coverage

File:lib/SEO/Inspector/Plugin/MetaDescriptionCheck.pm
Coverage:86.1%

linestmtbrancondsubtimecode
1package SEO::Inspector::Plugin::MetaDescriptionCheck;
2
3
5
5
5
1482
5
78
use strict;
4
5
5
5
9
5
91
use warnings;
5
5
5
5
9
3
16
use HTML::TreeBuilder;
6
7
7
4544
sub new { bless {}, shift }
8
9
0
0
sub name { 'MetaDescriptionCheck' }
10
11sub run {
12
5
6
    my ($self, $html) = @_;
13
14
5
11
    my $tree = HTML::TreeBuilder->new;
15
5
645
    $tree->parse_content($html);
16
17    # Find <meta name="description"> safely
18
5
1777
    my $meta_content;
19
5
13
    for my $el ($tree->find_by_tag_name('meta')) {
20
3
89
        next unless defined $el->attr('name') && $el->attr('name') eq 'description';
21
3
36
        $meta_content = $el->attr('content');
22
3
12
        last;
23    }
24
25
5
49
    $tree->delete;
26
27
5
174
    if ($meta_content) {
28
3
24
        return { status => 'ok', notes => 'meta description present' };
29    }
30
31
2
19
    return { status => 'warn', notes => 'missing meta description' };
32}
33
341;