line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package HTML::SocialMeta::Base; |
2
|
5
|
|
|
5
|
|
2868
|
use Moo; |
|
5
|
|
|
|
|
13
|
|
|
5
|
|
|
|
|
37
|
|
3
|
5
|
|
|
5
|
|
1679
|
use Carp; |
|
5
|
|
|
|
|
17
|
|
|
5
|
|
|
|
|
422
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
our $VERSION = '0.74004'; |
6
|
|
|
|
|
|
|
|
7
|
5
|
|
|
5
|
|
38
|
use MooX::LazierAttributes qw/rw ro lzy dhash lzy_str coe/; |
|
5
|
|
|
|
|
11
|
|
|
5
|
|
|
|
|
48
|
|
8
|
5
|
|
|
5
|
|
1039
|
use MooX::ValidateSubs; |
|
5
|
|
|
|
|
76
|
|
|
5
|
|
|
|
|
36
|
|
9
|
5
|
|
|
5
|
|
6123
|
use Coerce::Types::Standard qw/Str HashRef HTML StrSR/; |
|
5
|
|
|
|
|
96568
|
|
|
5
|
|
|
|
|
101
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
attributes( |
12
|
|
|
|
|
|
|
[qw(card_type card type name url)] => [ rw, HTML->by('encode_entity'), {lzy, coe} ], |
13
|
|
|
|
|
|
|
[qw(site fb_app_id site_name title description image creator operatingSystem app_country |
14
|
|
|
|
|
|
|
app_name app_id app_url player player_height player_width)] => [HTML->by('encode_entity'), {coe}], |
15
|
|
|
|
|
|
|
'image_alt' => [HTML->by('encode_entity'), {coe, lzy_str}], |
16
|
|
|
|
|
|
|
[qw(card_options build_fields)] => [HashRef,{dhash}], |
17
|
|
|
|
|
|
|
[qw(meta_attribute meta_namespace)] => [ro], |
18
|
|
|
|
|
|
|
); |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
validate_subs( |
21
|
|
|
|
|
|
|
create => { params => [ [ Str, 'card_type' ] ] }, |
22
|
|
|
|
|
|
|
build_meta_tags => { params => [ [Str] ] }, |
23
|
|
|
|
|
|
|
required_fields => { params => [ [Str] ] }, |
24
|
|
|
|
|
|
|
meta_option => { params => [ [Str] ] }, |
25
|
|
|
|
|
|
|
_generate_meta_tag => { params => [ [Str] ] }, |
26
|
|
|
|
|
|
|
_build_field => { params => [ [HashRef] ] }, |
27
|
|
|
|
|
|
|
_convert_field => { params => [ [StrSR->by(['_',':'])] ] }, |
28
|
|
|
|
|
|
|
_no_card_type => { params => [ [Str] ] } |
29
|
|
|
|
|
|
|
); |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
sub create { |
32
|
|
|
|
|
|
|
if ( my $option = $_[0]->card_options->{ $_[1] } ) { |
33
|
|
|
|
|
|
|
return $_[0]->$option; |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
return $_[0]->_no_card_type( $_[1] ); |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
sub build_meta_tags { |
39
|
|
|
|
|
|
|
my @meta_tags; |
40
|
|
|
|
|
|
|
$_[0]->meta_attribute eq q{itemprop} and push @meta_tags, $_[0]->item_type; |
41
|
|
|
|
|
|
|
foreach ( $_[0]->required_fields( $_[1] ) ) { |
42
|
|
|
|
|
|
|
$_[0]->_validate_field_value($_); |
43
|
|
|
|
|
|
|
push @meta_tags, $_[0]->_generate_meta_tag($_); |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
return join "\n", @meta_tags; |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
sub required_fields { |
49
|
|
|
|
|
|
|
return |
50
|
|
|
|
|
|
|
defined $_[0]->build_fields->{ $_[1] } |
51
|
|
|
|
|
|
|
? @{ $_[0]->build_fields->{ $_[1] } } |
52
|
|
|
|
|
|
|
: (); |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
sub meta_option { |
56
|
|
|
|
|
|
|
my $option = $_[0]->card_options->{$_[1]}; |
57
|
|
|
|
|
|
|
$option =~ s{^create_}{}xms; |
58
|
|
|
|
|
|
|
return $option; |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
sub _validate_field_value { |
62
|
244
|
|
|
244
|
|
381
|
my $lame = $_[1]; # instantiate a default |
63
|
244
|
100
|
|
|
|
2217
|
defined $_[0]->$lame and return 1; |
64
|
2
|
|
|
|
|
52
|
croak sprintf q{you have not set this field value %s}, $lame; |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
sub _generate_meta_tag { |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
# fields that don't start with app, player, or image generate a single tag |
70
|
|
|
|
|
|
|
$_[1] !~ m{^app|player|fb|image}xms |
71
|
|
|
|
|
|
|
and return $_[0]->_build_field( { field => $_[1] } ); |
72
|
|
|
|
|
|
|
return |
73
|
|
|
|
|
|
|
map { $_[0]->_build_field( { field => $_[1], %{$_} } ) } |
74
|
|
|
|
|
|
|
@{ $_[0]->_convert_field( $_[1] ) }; |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
sub _build_field { |
78
|
|
|
|
|
|
|
return sprintf q{}, $_[0]->meta_attribute, |
79
|
|
|
|
|
|
|
( $_[1]->{ignore_meta_namespace} || $_[0]->meta_namespace ), |
80
|
|
|
|
|
|
|
( defined $_[1]->{field_type} ? $_[1]->{field_type} : $_[1]->{field} ), |
81
|
|
|
|
|
|
|
$_[0]->{$_[1]->{field}}; |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
sub _convert_field { |
85
|
|
|
|
|
|
|
return $_[0]->provider_convert( $_[1] ); |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
sub _no_card_type { |
89
|
|
|
|
|
|
|
return croak sprintf |
90
|
|
|
|
|
|
|
q{this card type does not exist - %s try one of these summary, featured_image, app, player}, |
91
|
|
|
|
|
|
|
$_[1]; |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
# |
95
|
|
|
|
|
|
|
# The End |
96
|
|
|
|
|
|
|
# |
97
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable; |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
1; |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
__END__ |