File Coverage

blib/lib/HTML/SocialMeta.pm
Criterion Covered Total %
statement 29 29 100.0
branch 10 10 100.0
condition 3 3 100.0
subroutine 10 10 100.0
pod n/a
total 52 52 100.0


line stmt bran cond sub pod time code
1             package HTML::SocialMeta;
2 5     5   77559 use Moo;
  5         57773  
  5         22  
3 5     5   10367 use List::MoreUtils qw(uniq);
  5         62757  
  5         34  
4              
5 5     5   8031 use HTML::SocialMeta::Twitter;
  5         18  
  5         162  
6 5     5   2307 use HTML::SocialMeta::OpenGraph;
  5         12  
  5         168  
7              
8 5     5   34 use MooX::LazierAttributes qw/lzy bld coe/;
  5         9  
  5         18  
9 5     5   749 use MooX::ValidateSubs;
  5         11  
  5         21  
10 5     5   4071 use Coerce::Types::Standard qw/HTML Str Object StrToArray/;
  5         10  
  5         33  
11              
12             our $VERSION = '0.74004';
13              
14             our %encode;
15             BEGIN {
16 5     5   6904 %encode = ( q{&} => q{&}, q{"} => q{"}, q{'} => q{'}, q{<} => q{<}, q{>} => q{>} );
17 5         2188 $encode{regex} = join "|", keys %encode;
18             }
19              
20             attributes(
21             [qw(card_type card site site_name title description image image_alt url creator operatingSystem
22             app_country app_name app_id app_url player player_height player_width fb_app_id)] => [ HTML->by('encode_entity'), {lzy, coe} ],
23             [qw(twitter opengraph)] => [ Object, { lzy, bld } ],
24             social => [ sub { [qw/twitter opengraph/] } ],
25             );
26              
27             validate_subs(
28             create => {
29             params => [ [ Str, 'card_type' ], [ StrToArray->by('\s'), 'social' ] ], # I expect this to be an arrayref
30             },
31             required_fields => {
32             params => [ [ Str, 'card_type' ], [ StrToArray->by('\s'), 'social' ] ],
33             },
34             );
35              
36             sub create {
37             return join "\n", map { $_[0]->$_->create( $_[1] ) } @{ $_[2] }; # it doesn't coerce my value
38             }
39              
40             sub required_fields {
41             return uniq(
42             map { $_[0]->$_->required_fields( $_[0]->$_->meta_option( $_[1] ) ) }
43             @{ $_[2] } );
44             }
45              
46             sub _build_twitter {
47 9 100   9   1983 my %args = map { defined $_[0]->$_ ? ( $_ => $_[0]->$_ ) : () }
  144         402  
48             qw/card_type site title description image image_alt url creator
49             operatingSystem app_country app_name app_id app_url
50             player player_width player_height/;
51            
52             HTML::SocialMeta::Twitter->new(
53             (
54 9 100       29 map { defined $_[0]->$_ ? ( $_ => $_[0]->$_ ) : () }
  144         473  
55             qw/card_type site title description image image_alt url creator
56             operatingSystem app_country app_name app_id app_url
57             player player_width player_height/
58             )
59             );
60             }
61              
62             sub _build_opengraph {
63             HTML::SocialMeta::OpenGraph->new(
64             (
65 8 100 100 8   1753 map { defined $_[0]->$_ ? ( $_ => $_[0]->$_ ) : () }
  88 100       1238  
    100          
66             qw/card_type site_name title description image operatingSystem player
67             image_alt player_width player_height fb_app_id/
68             ),
69             (
70             $_[0]->app_url || $_[0]->url
71             ? ( url => $_[0]->app_url ? $_[0]->app_url : $_[0]->url )
72             : ()
73             ),
74             );
75             }
76              
77             #
78             # The End
79             #
80             __PACKAGE__->meta->make_immutable;
81              
82             1;
83              
84             __END__