line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package HTML::SocialMeta::Base; |
2
|
5
|
|
|
5
|
|
1955
|
use Moo; |
|
5
|
|
|
|
|
7
|
|
|
5
|
|
|
|
|
19
|
|
3
|
5
|
|
|
5
|
|
833
|
use Carp; |
|
5
|
|
|
|
|
5
|
|
|
5
|
|
|
|
|
3107
|
|
4
|
|
|
|
|
|
|
our $VERSION = '0.6'; |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
# A list of fields which the cards may possibly use |
7
|
|
|
|
|
|
|
has [qw(card_type card type name url)] => ( |
8
|
|
|
|
|
|
|
is => 'rw', |
9
|
|
|
|
|
|
|
lazy => 1, |
10
|
|
|
|
|
|
|
default => q{}, |
11
|
|
|
|
|
|
|
); |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
has [ |
14
|
|
|
|
|
|
|
qw(site fb_app_id site_name title description image creator operatingSystem app_country app_name app_id app_url player player_height player_width) |
15
|
|
|
|
|
|
|
] => ( |
16
|
|
|
|
|
|
|
is => 'ro', |
17
|
|
|
|
|
|
|
lazy => 1, |
18
|
|
|
|
|
|
|
default => q{}, |
19
|
|
|
|
|
|
|
); |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
# default should be overridden by sub-classes |
22
|
|
|
|
|
|
|
has [qw(card_options build_fields)] => ( |
23
|
|
|
|
|
|
|
is => 'ro', |
24
|
|
|
|
|
|
|
default => sub { {} }, |
25
|
|
|
|
|
|
|
); |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
sub create { |
28
|
21
|
|
|
21
|
1
|
1398
|
my ( $self, $card_type ) = @_; |
29
|
|
|
|
|
|
|
|
30
|
21
|
|
66
|
|
|
48
|
$card_type ||= $self->card_type; |
31
|
|
|
|
|
|
|
|
32
|
21
|
50
|
|
|
|
356
|
if ( my $option = $self->card_options->{$card_type} ) { |
33
|
|
|
|
|
|
|
|
34
|
21
|
|
|
|
|
60
|
return $self->$option; |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
0
|
|
|
|
|
0
|
return $self->_no_card_type($card_type); |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
sub build_meta_tags { |
41
|
31
|
|
|
31
|
1
|
154
|
my ( $self, $field_type ) = @_; |
42
|
|
|
|
|
|
|
|
43
|
31
|
|
|
|
|
302
|
my @meta_tags; |
44
|
|
|
|
|
|
|
|
45
|
31
|
50
|
|
|
|
82
|
if ( $self->meta_attribute eq q{itemprop} ) { |
46
|
0
|
|
|
|
|
0
|
push @meta_tags, $self->item_type; |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
31
|
|
|
|
|
57
|
foreach my $field ( $self->required_fields($field_type) ) { |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
# check the field has a value set |
52
|
201
|
|
|
|
|
1063
|
$self->_validate_field_value($field); |
53
|
|
|
|
|
|
|
|
54
|
199
|
|
|
|
|
301
|
push @meta_tags, $self->_generate_meta_tag($field); |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
29
|
|
|
|
|
219
|
return join "\n", @meta_tags; |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
sub required_fields { |
61
|
37
|
|
|
37
|
1
|
31
|
my ( $self, $field ) = @_; |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
return |
64
|
|
|
|
|
|
|
exists $self->build_fields->{$field} |
65
|
37
|
50
|
|
|
|
74
|
? @{ $self->build_fields->{$field} } |
|
37
|
|
|
|
|
107
|
|
66
|
|
|
|
|
|
|
: (); |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
sub _validate_field_value { |
70
|
201
|
|
|
201
|
|
168
|
my ( $self, $field ) = @_; |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
# look to see we have the fields attribute set |
73
|
201
|
100
|
|
|
|
2283
|
croak q{you have not set this field value } . $field |
74
|
|
|
|
|
|
|
if !$self->$field; |
75
|
|
|
|
|
|
|
|
76
|
199
|
|
|
|
|
10835
|
return; |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
sub _generate_meta_tag { |
80
|
199
|
|
|
199
|
|
167
|
my ( $self, $field ) = @_; |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
# fields that don't start with app or player generate a single tag |
83
|
199
|
100
|
|
|
|
691
|
return $self->_build_field( { field => $field } ) |
84
|
|
|
|
|
|
|
if $field !~ m{(?:app|player|fb)}xms; |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
# fields that start with app or player generate multiple tags |
87
|
54
|
|
|
|
|
55
|
my @tags = (); |
88
|
|
|
|
|
|
|
|
89
|
54
|
|
|
|
|
42
|
for ( @{ $self->_convert_field($field) } ) { |
|
54
|
|
|
|
|
86
|
|
90
|
66
|
|
|
|
|
838
|
push @tags, $self->_build_field( { field => $field, %{$_} } ); |
|
66
|
|
|
|
|
179
|
|
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
|
93
|
54
|
|
|
|
|
486
|
return @tags; |
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
sub _build_field { |
97
|
211
|
|
|
211
|
|
162
|
my ( $self, $args ) = @_; |
98
|
|
|
|
|
|
|
|
99
|
211
|
|
66
|
|
|
377
|
my $field_type = $args->{field_type} || $args->{field}; |
100
|
|
|
|
|
|
|
my $meta_namespace = |
101
|
211
|
|
66
|
|
|
535
|
$args->{ignore_meta_namespace} || $self->meta_namespace; |
102
|
211
|
|
|
|
|
146
|
my $field = $args->{field}; |
103
|
|
|
|
|
|
|
|
104
|
211
|
|
|
|
|
2936
|
return sprintf q{}, |
105
|
|
|
|
|
|
|
$self->meta_attribute, $meta_namespace, $field_type, $self->$field; |
106
|
|
|
|
|
|
|
} |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
sub _convert_field { |
109
|
54
|
|
|
54
|
|
45
|
my ( $self, $field ) = @_; |
110
|
|
|
|
|
|
|
|
111
|
54
|
|
|
|
|
67
|
$field =~ tr/_/:/; |
112
|
|
|
|
|
|
|
|
113
|
54
|
|
|
|
|
96
|
return $self->provider_convert($field); |
114
|
|
|
|
|
|
|
} |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
sub meta_option { |
117
|
6
|
|
|
6
|
0
|
118
|
my ( $self, $card_type ) = @_; |
118
|
|
|
|
|
|
|
|
119
|
6
|
50
|
|
|
|
21
|
if ( my $option = $self->card_options->{$card_type} ) { |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
# remove create_ and we have the card type |
122
|
6
|
|
|
|
|
15
|
$option =~ s{^create_}{}xms; |
123
|
6
|
|
|
|
|
14
|
return $option; |
124
|
|
|
|
|
|
|
} |
125
|
|
|
|
|
|
|
} |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
sub _no_card_type { |
128
|
0
|
|
|
0
|
|
|
my ( $self, $card_type ) = @_; |
129
|
0
|
|
|
|
|
|
return croak |
130
|
|
|
|
|
|
|
q{this card type does not exist try one of these summary, featured_image, app, player}; |
131
|
|
|
|
|
|
|
} |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
# |
134
|
|
|
|
|
|
|
# The End |
135
|
|
|
|
|
|
|
# |
136
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable; |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
1; |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
__END__ |