| 1 | package HTML::SocialMeta::OpenGraph; | ||||||||||
| 2 | 5 | ▶ | use Moose; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 3 | 5 | ▶ | use namespace::autoclean; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 5 | ▶ | use Carp; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | |||||||||||
| 6 | 5 | our $VERSION = '0.4'; | |||||||||
| 7 | |||||||||||
| 8 | 5 | extends 'HTML::SocialMeta::Base'; | |||||||||
| 9 | |||||||||||
| 10 | # Provider Specific Fields | ||||||||||
| 11 | 5 | has 'meta_attribute' => | |||||||||
| 12 | ( isa => 'Str', is => 'ro', required => 1, default => 'property' ); | ||||||||||
| 13 | 5 | has 'meta_namespace' => | |||||||||
| 14 | ( isa => 'Str', is => 'ro', required => 1, default => 'og' ); | ||||||||||
| 15 | |||||||||||
| 16 | 5 | has 'fb_namespace' => ( isa => 'Str', is => 'rw', lazy => 1, default => q{} ); | |||||||||
| 17 | |||||||||||
| 18 | has '+card_options' => ( | ||||||||||
| 19 | default => sub { | ||||||||||
| 20 | return { | ||||||||||
| 21 | 7 | ▶ | summary => q(create_thumbnail), | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 22 | featured_image => q(create_article), | ||||||||||
| 23 | player => q(create_video), | ||||||||||
| 24 | app => q(create_product), | ||||||||||
| 25 | }; | ||||||||||
| 26 | }, | ||||||||||
| 27 | 5 | ); | |||||||||
| 28 | |||||||||||
| 29 | has '+build_fields' => ( | ||||||||||
| 30 | default => sub { | ||||||||||
| 31 | return { | ||||||||||
| 32 | 7 | ▶ | thumbnail => | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 33 | [qw(type title description url image site_name fb_app_id)], | ||||||||||
| 34 | article => | ||||||||||
| 35 | [qw(type title description url image site_name fb_app_id)], | ||||||||||
| 36 | video => [ | ||||||||||
| 37 | qw(type site_name url title image description player player_width player_height fb_app_id) | ||||||||||
| 38 | ], | ||||||||||
| 39 | product => [qw(type title image description url fb_app_id)] | ||||||||||
| 40 | }; | ||||||||||
| 41 | }, | ||||||||||
| 42 | 5 | ); | |||||||||
| 43 | |||||||||||
| 44 | sub create_thumbnail { | ||||||||||
| 45 | 3 | ▶ | my ($self) = @_; | ||||||||
|
Subroutine
create_thumbnail: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 46 | |||||||||||
| 47 | 3 | $self->type('thumbnail'); | |||||||||
| 48 | |||||||||||
| 49 | 3 | return $self->build_meta_tags( $self->type ); | |||||||||
| 50 | } | ||||||||||
| 51 | |||||||||||
| 52 | sub create_article { | ||||||||||
| 53 | 4 | ▶ | my ($self) = @_; | ||||||||
|
Subroutine
create_article: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 54 | |||||||||||
| 55 | 4 | $self->type('article'); | |||||||||
| 56 | |||||||||||
| 57 | 4 | return $self->build_meta_tags( $self->type ); | |||||||||
| 58 | } | ||||||||||
| 59 | |||||||||||
| 60 | sub create_video { | ||||||||||
| 61 | 3 | ▶ | my ($self) = @_; | ||||||||
|
Subroutine
create_video: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 62 | |||||||||||
| 63 | 3 | $self->type('video'); | |||||||||
| 64 | |||||||||||
| 65 | 3 | return $self->build_meta_tags( $self->type ); | |||||||||
| 66 | } | ||||||||||
| 67 | |||||||||||
| 68 | sub create_product { | ||||||||||
| 69 | 3 | ▶ | my ($self) = @_; | ||||||||
|
Subroutine
create_product: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 70 | |||||||||||
| 71 | 3 | $self->type('product'); | |||||||||
| 72 | |||||||||||
| 73 | 3 | return $self->build_meta_tags( $self->type ); | |||||||||
| 74 | } | ||||||||||
| 75 | |||||||||||
| 76 | sub provider_convert { | ||||||||||
| 77 | 21 | ▶ | my ( $self, $field ) = @_; | ||||||||
|
Subroutine
provider_convert: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||
| 78 | |||||||||||
| 79 | 21 | ▶ | if ( $field =~ m{^fb:}xms ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 80 | 12 | $field =~ s{^fb:}{}xms; | |||||||||
| 81 | 12 | return [ { field_type => $field, ignore_meta_namespace => 'fb' } ]; | |||||||||
| 82 | } | ||||||||||
| 83 | |||||||||||
| 84 | 9 | $field =~ s{^player}{video}xms; | |||||||||
| 85 | |||||||||||
| 86 | return [ | ||||||||||
| 87 | 9 | ▶ | { field_type => $field . ':url' }, | ||||||||
|
Branch: 1 branch
| |||||||||||
| 88 | { field_type => $field . ':secure_url' } | ||||||||||
| 89 | ] | ||||||||||
| 90 | if $field =~ m{^video$}xms; | ||||||||||
| 91 | |||||||||||
| 92 | 6 | return [ { field_type => $field } ]; | |||||||||
| 93 | } | ||||||||||
| 94 | |||||||||||
| 95 | # | ||||||||||
| 96 | # The End | ||||||||||
| 97 | # | ||||||||||
| 98 | 5 | __PACKAGE__->meta->make_immutable; | |||||||||
| 99 | |||||||||||
| 100 | 5 | 1; | |||||||||
| 101 | |||||||||||
| 102 | __END__ | ||||||||||
| 103 | |||||||||||
| 104 | =head1 NAME | ||||||||||
| 105 | |||||||||||
| 106 | HTML::SocialMeta::OpenGraph | ||||||||||
| 107 | |||||||||||
| 108 | =head1 VERSION | ||||||||||
| 109 | |||||||||||
| 110 | Version 0.4 | ||||||||||
| 111 | |||||||||||
| 112 | =cut | ||||||||||
| 113 | |||||||||||
| 114 | =head1 DESCRIPTION | ||||||||||
| 115 | |||||||||||
| 116 | Base class for creating OpenGraph meta data | ||||||||||
| 117 | |||||||||||
| 118 | =head1 SYNOPSIS | ||||||||||
| 119 | |||||||||||
| 120 | $opengraph_meta => HTML::Social::OpenGraph->new( | ||||||||||
| 121 | card_type => 'summary', | ||||||||||
| 122 | site => '@example_twitter', | ||||||||||
| 123 | site_name => 'Example Site, anything', | ||||||||||
| 124 | title => 'You can have any title you wish here', | ||||||||||
| 125 | description => 'Description goes here may have to do a little validation', | ||||||||||
| 126 | image => 'www.urltoimage.com/blah.jpg', | ||||||||||
| 127 | url => 'www.someurl.com', | ||||||||||
| 128 | app_url_store => 'test', - optional | ||||||||||
| 129 | player => 'www.urltovideo.com/blah.jpg', | ||||||||||
| 130 | player_width => '500', | ||||||||||
| 131 | player_height => '500', | ||||||||||
| 132 | ); | ||||||||||
| 133 | |||||||||||
| 134 | $opengraph->create('summary featured_image app player'); | ||||||||||
| 135 | |||||||||||
| 136 | $opengraph->create_thumnail; | ||||||||||
| 137 | $opengraph->create_article; | ||||||||||
| 138 | $opengraph->create_product'; | ||||||||||
| 139 | $opengraph->create_video; | ||||||||||
| 140 | |||||||||||
| 141 | |||||||||||
| 142 | |||||||||||
| 143 | =head1 SUBROUTINES/METHODS | ||||||||||
| 144 | |||||||||||
| 145 | =head2 card_options | ||||||||||
| 146 | |||||||||||
| 147 | An Hash Reference of card options available for this meta provider, it is used to map the create function when create is called. | ||||||||||
| 148 | |||||||||||
| 149 | =cut | ||||||||||
| 150 | |||||||||||
| 151 | =head2 build_fields | ||||||||||
| 152 | |||||||||||
| 153 | An Hash Reference of fields that are attached to the selected card: | ||||||||||
| 154 | |||||||||||
| 155 | =cut | ||||||||||
| 156 | |||||||||||
| 157 | =head2 create_thumbnail | ||||||||||
| 158 | |||||||||||
| 159 | Generate OpenGraph Thumbnail meta data | ||||||||||
| 160 | |||||||||||
| 161 | =cut | ||||||||||
| 162 | |||||||||||
| 163 | =head2 create_article | ||||||||||
| 164 | |||||||||||
| 165 | Generate OpenGraph Article meta data | ||||||||||
| 166 | |||||||||||
| 167 | =cut | ||||||||||
| 168 | |||||||||||
| 169 | =head2 create_product | ||||||||||
| 170 | |||||||||||
| 171 | Generate OpenGraph Product meta data | ||||||||||
| 172 | |||||||||||
| 173 | =cut | ||||||||||
| 174 | |||||||||||
| 175 | =head2 create_video | ||||||||||
| 176 | |||||||||||
| 177 | Generate OpenGraph Video meta data | ||||||||||
| 178 | |||||||||||
| 179 | =cut | ||||||||||
| 180 | |||||||||||
| 181 | =head1 AUTHOR | ||||||||||
| 182 | |||||||||||
| 183 | Robert Acock <ThisUsedToBeAnEmail@gmail.com> | ||||||||||
| 184 | |||||||||||
| 185 | With special thanks to: | ||||||||||
| 186 | Robert Haliday <robh@cpan.org> | ||||||||||
| 187 | |||||||||||
| 188 | =head1 TODO | ||||||||||
| 189 | |||||||||||
| 190 | * Add support for more social Card Types / Meta Providers | ||||||||||
| 191 | |||||||||||
| 192 | =head1 BUGS AND LIMITATIONS | ||||||||||
| 193 | |||||||||||
| 194 | Most probably. Please report any bugs at http://rt.cpan.org/. | ||||||||||
| 195 | |||||||||||
| 196 | =head1 INCOMPATIBILITIES | ||||||||||
| 197 | |||||||||||
| 198 | =head1 DEPENDENCIES | ||||||||||
| 199 | |||||||||||
| 200 | =head1 CONFIGURATION AND ENVIRONMENT | ||||||||||
| 201 | |||||||||||
| 202 | =head1 DIAGNOSTICS | ||||||||||
| 203 | |||||||||||
| 204 | =head1 LICENSE AND COPYRIGHT | ||||||||||
| 205 | |||||||||||
| 206 | Copyright 2015 Robert Acock. | ||||||||||
| 207 | |||||||||||
| 208 | This program is free software; you can redistribute it and/or modify it | ||||||||||
| 209 | under the terms of the the Artistic License (2.0). You may obtain a | ||||||||||
| 210 | copy of the full license at: | ||||||||||
| 211 | |||||||||||
| 212 | L<http://www.perlfoundation.org/artistic_license_2_0> | ||||||||||
| 213 | |||||||||||
| 214 | Any use, modification, and distribution of the Standard or Modified | ||||||||||
| 215 | Versions is governed by this Artistic License. By using, modifying or | ||||||||||
| 216 | distributing the Package, you accept this license. Do not use, modify, | ||||||||||
| 217 | or distribute the Package, if you do not accept this license. | ||||||||||
| 218 | |||||||||||
| 219 | If your Modified Version has been derived from a Modified Version made | ||||||||||
| 220 | by someone other than you, you are nevertheless required to ensure that | ||||||||||
| 221 | your Modified Version complies with the requirements of this license. | ||||||||||
| 222 | |||||||||||
| 223 | This license does not grant you the right to use any trademark, service | ||||||||||
| 224 | mark, tradename, or logo of the Copyright Holder. | ||||||||||
| 225 | |||||||||||
| 226 | This license includes the non-exclusive, worldwide, free-of-charge | ||||||||||
| 227 | patent license to make, have made, use, offer to sell, sell, import and | ||||||||||
| 228 | otherwise transfer the Package with respect to any patent claims | ||||||||||
| 229 | licensable by the Copyright Holder that are necessarily infringed by the | ||||||||||
| 230 | Package. If you institute patent litigation (including a cross-claim or | ||||||||||
| 231 | counterclaim) against any party alleging that the Package constitutes | ||||||||||
| 232 | direct or contributory patent infringement, then this Artistic License | ||||||||||
| 233 | to you shall terminate on the date that such litigation is filed. | ||||||||||
| 234 | |||||||||||
| 235 | Disclaimer of Warranty: THE PACKAGE IS PROVIDED BY THE COPYRIGHT HOLDER | ||||||||||
| 236 | AND CONTRIBUTORS "AS IS' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES. | ||||||||||
| 237 | THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR | ||||||||||
| 238 | PURPOSE, OR NON-INFRINGEMENT ARE DISCLAIMED TO THE EXTENT PERMITTED BY | ||||||||||
| 239 | YOUR LOCAL LAW. UNLESS REQUIRED BY LAW, NO COPYRIGHT HOLDER OR | ||||||||||
| 240 | CONTRIBUTOR WILL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, OR | ||||||||||
| 241 | CONSEQUENTIAL DAMAGES ARISING IN ANY WAY OUT OF THE USE OF THE PACKAGE, | ||||||||||
| 242 | EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||||||||||
| 243 | |||||||||||
| 244 | |||||||||||
| 245 | |||||||||||