File Coverage

blib/lib/HTML/SocialMeta.pm
Criterion Covered Total %
statement 28 28 100.0
branch 2 2 100.0
condition 2 3 66.6
subroutine 8 8 100.0
pod 2 4 50.0
total 42 45 93.3


line stmt bran cond sub pod time code
1             package HTML::SocialMeta;
2 5     5   98225 use Moo;
  5         46748  
  5         21  
3 5     5   7448 use List::MoreUtils qw(uniq);
  5         38806  
  5         25  
4              
5 5     5   4044 use HTML::SocialMeta::Twitter;
  5         12  
  5         137  
6 5     5   1797 use HTML::SocialMeta::OpenGraph;
  5         9  
  5         1653  
7              
8             our $VERSION = '0.6';
9              
10             has 'card_type' => ( is => 'rw', lazy => 1, default => q{} );
11             has [
12             qw(card site site_name title description image url creator operatingSystem app_country app_name app_id app_url player player_height player_width fb_app_id)
13             ] => (
14             is => 'ro',
15             lazy => 1,
16             default => q{},
17             );
18              
19             has 'twitter' => (
20             is => 'ro',
21             lazy => 1,
22             builder => 'build_twitter',
23             );
24              
25             has 'opengraph' => (
26             is => 'ro',
27             lazy => 1,
28             builder => 'build_opengraph',
29             );
30              
31             sub create {
32 5     5 1 3351 my ( $self, $card_type ) = @_;
33              
34 5   66     15 $card_type ||= $self->card_type;
35              
36 5         378 $self->card_type($card_type);
37              
38             my @meta_tags =
39 5         19 map { $self->$_->create( $self->card_type ) } qw/twitter opengraph/;
  10         121  
40              
41 5         20 return join "\n", @meta_tags;
42             }
43              
44             sub required_fields {
45 3     3 1 1393 my ( $self, $card_type ) = @_;
46              
47             my @meta_tags =
48 3         5 map { $self->$_->required_fields( $self->$_->meta_option($card_type) ) }
  6         99  
49             qw/twitter opengraph/;
50              
51 3         31 my @required_fields = uniq(@meta_tags);
52              
53 3         16 return @required_fields;
54             }
55              
56             sub build_twitter {
57 8     8 0 5636 my $self = shift;
58              
59 8         86 return HTML::SocialMeta::Twitter->new(
60             card_type => $self->card_type,
61             site => $self->site,
62             title => $self->title,
63             description => $self->description,
64             image => $self->image,
65             url => $self->url,
66             creator => $self->creator,
67             operatingSystem => $self->operatingSystem,
68             app_country => $self->app_country,
69             app_name => $self->app_name,
70             app_id => $self->app_id,
71             app_url => $self->app_url,
72             player => $self->player,
73             player_width => $self->player_width,
74             player_height => $self->player_height,
75             );
76             }
77              
78             sub build_opengraph {
79 7     7 0 4426 my $self = shift;
80              
81 7 100       83 my $url = $self->app_url ? $self->app_url : $self->url;
82              
83 7         739 return HTML::SocialMeta::OpenGraph->new(
84             card_type => $self->card_type,
85             site_name => $self->site_name,
86             title => $self->title,
87             description => $self->description,
88             image => $self->image,
89             url => $url,
90             operatingSystem => $self->operatingSystem,
91             player => $self->player,
92             player_width => $self->player_width,
93             player_height => $self->player_height,
94             fb_app_id => $self->fb_app_id,
95             );
96             }
97              
98             #
99             # The End
100             #
101             __PACKAGE__->meta->make_immutable;
102              
103             1;
104              
105             __END__