File Coverage

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

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