| File: | lib/SEO/Inspector/Plugin/MetaDescriptionCheck.pm | 
| Coverage: | 86.1% | 
| line | stmt | bran | cond | sub | time | code | 
|---|---|---|---|---|---|---|
| 1 | package SEO::Inspector::Plugin::MetaDescriptionCheck; | |||||
| 2 | ||||||
| 3 | 5 5 5 | 2865 5 78 | use strict; | |||
| 4 | 5 5 5 | 9 6 109 | use warnings; | |||
| 5 | 5 5 5 | 1550 64817 20 | use HTML::TreeBuilder; | |||
| 6 | ||||||
| 7 | 7 | 4367 | sub new { bless {}, shift } | |||
| 8 | ||||||
| 9 | 0 | 0 | sub name { 'MetaDescriptionCheck' } | |||
| 10 | ||||||
| 11 | sub run { | |||||
| 12 | 5 | 11 | my ($self, $html) = @_; | |||
| 13 | ||||||
| 14 | 5 | 10 | my $tree = HTML::TreeBuilder->new; | |||
| 15 | 5 | 524 | $tree->parse_content($html); | |||
| 16 | ||||||
| 17 | # Find <meta name="description"> safely | |||||
| 18 | 5 | 1751 | my $meta_content; | |||
| 19 | 5 | 10 | 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 | 35 | $meta_content = $el->attr('content'); | |||
| 22 | 3 | 13 | last; | |||
| 23 | } | |||||
| 24 | ||||||
| 25 | 5 | 42 | $tree->delete; | |||
| 26 | ||||||
| 27 | 5 | 157 | if ($meta_content) { | |||
| 28 | 3 | 23 | return { status => 'ok', notes => 'meta description present' }; | |||
| 29 | } | |||||
| 30 | ||||||
| 31 | 2 | 11 | return { status => 'warn', notes => 'missing meta description' }; | |||
| 32 | } | |||||
| 33 | ||||||
| 34 | 1; | |||||