| File: | lib/SEO/Inspector/Plugin/TitleCheck.pm | 
| Coverage: | 90.9% | 
| line | stmt | bran | cond | sub | time | code | 
|---|---|---|---|---|---|---|
| 1 | package SEO::Inspector::Plugin::TitleCheck; | |||||
| 2 | ||||||
| 3 | 5 5 5 | 1433 5 77 | use strict; | |||
| 4 | 5 5 5 | 10 3 105 | use warnings; | |||
| 5 | 5 5 5 | 8 5 15 | use HTML::TreeBuilder; | |||
| 6 | ||||||
| 7 | 7 | 28 | sub new { bless {}, shift } | |||
| 8 | ||||||
| 9 | 0 | 0 | sub name { 'TitleCheck' } | |||
| 10 | ||||||
| 11 | sub run { | |||||
| 12 | 5 | 6 | my ($self, $html) = @_; | |||
| 13 | ||||||
| 14 | 5 | 13 | my $tree = HTML::TreeBuilder->new; | |||
| 15 | 5 | 617 | $tree->parse_content($html); | |||
| 16 | ||||||
| 17 | # Find the <title> element safely | |||||
| 18 | 5 | 1735 | my $title; | |||
| 19 | 5 | 12 | for my $el ($tree->find_by_tag_name('title')) { | |||
| 20 | 4 | 109 | $title = $el->as_text; | |||
| 21 | 4 | 44 | last; | |||
| 22 | } | |||||
| 23 | ||||||
| 24 | 5 | 35 | $tree->delete; | |||
| 25 | ||||||
| 26 | 5 | 181 | if ($title && length $title) { | |||
| 27 | 4 | 27 | return { status => 'ok', notes => 'title present' }; | |||
| 28 | } | |||||
| 29 | ||||||
| 30 | 1 | 10 | return { status => 'error', notes => 'missing title' }; | |||
| 31 | } | |||||
| 32 | ||||||
| 33 | 1; | |||||