File Coverage

blib/lib/WWW/DuckDuckGo/Link.pm
Criterion Covered Total %
statement 19 19 100.0
branch 5 8 62.5
condition 2 3 66.6
subroutine 6 6 100.0
pod 0 1 0.0
total 32 37 86.4


line stmt bran cond sub pod time code
1             package WWW::DuckDuckGo::Link;
2             BEGIN {
3 2     2   930 $WWW::DuckDuckGo::Link::AUTHORITY = 'cpan:DDG';
4             }
5             {
6             $WWW::DuckDuckGo::Link::VERSION = '0.016';
7             }
8             # ABSTRACT: A DuckDuckGo Link definition
9              
10 2     2   15 use Moo;
  2         4  
  2         14  
11 2     2   1576 use WWW::DuckDuckGo::Icon;
  2         6  
  2         73  
12 2     2   16 use URI;
  2         4  
  2         551  
13              
14             sub by {
15 3     3 0 3116 my ( $class, $link_result ) = @_;
16 3         5 my %params;
17 3 50       14 $params{result} = $link_result->{Result} if $link_result->{Result};
18 3 50       21 $params{first_url} = URI->new($link_result->{FirstURL}) if $link_result->{FirstURL};
19 3 100 66     223 $params{icon} = $class->_icon_class->by($link_result->{Icon}) if ref $link_result->{Icon} eq 'HASH' and %{$link_result->{Icon}};
  3         22  
20 3 50       49 $params{text} = $link_result->{Text} if $link_result->{Text};
21 3         60 __PACKAGE__->new(%params);
22             }
23              
24 1     1   7 sub _icon_class { 'WWW::DuckDuckGo::Icon' }
25              
26             has result => (
27             is => 'ro',
28             predicate => 'has_result',
29             );
30              
31             has first_url => (
32             is => 'ro',
33             predicate => 'has_first_url',
34             );
35              
36             has icon => (
37             is => 'ro',
38             predicate => 'has_icon',
39             );
40              
41             has text => (
42             is => 'ro',
43             predicate => 'has_text',
44             );
45              
46             1;
47              
48             __END__