| 1 | package Facebook::InstantArticle::Figure; | ||||||||||||||
| 2 | 2 | ▶ | use Moose; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 3 | 2 | ▶ | use namespace::autoclean; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 4 | |||||||||||||||
| 5 | 2 | extends 'Facebook::InstantArticle::BaseElement'; | |||||||||||||
| 6 | |||||||||||||||
| 7 | 2 | has 'source' => ( | |||||||||||||
| 8 | isa => 'Str', | ||||||||||||||
| 9 | is => 'rw', | ||||||||||||||
| 10 | required => 1, | ||||||||||||||
| 11 | default => '', | ||||||||||||||
| 12 | ); | ||||||||||||||
| 13 | |||||||||||||||
| 14 | 2 | has 'caption' => ( | |||||||||||||
| 15 | isa => 'Str', | ||||||||||||||
| 16 | is => 'rw', | ||||||||||||||
| 17 | required => 0, | ||||||||||||||
| 18 | default => '', | ||||||||||||||
| 19 | ); | ||||||||||||||
| 20 | |||||||||||||||
| 21 | 2 | has 'enable_comments' => ( | |||||||||||||
| 22 | isa => 'Bool', | ||||||||||||||
| 23 | is => 'rw', | ||||||||||||||
| 24 | required => 0, | ||||||||||||||
| 25 | default => 0, | ||||||||||||||
| 26 | ); | ||||||||||||||
| 27 | |||||||||||||||
| 28 | 2 | has 'enable_likes' => ( | |||||||||||||
| 29 | isa => 'Bool', | ||||||||||||||
| 30 | is => 'rw', | ||||||||||||||
| 31 | required => 0, | ||||||||||||||
| 32 | default => 0, | ||||||||||||||
| 33 | ); | ||||||||||||||
| 34 | |||||||||||||||
| 35 | 2 | has 'presentation' => ( | |||||||||||||
| 36 | isa => 'Str', | ||||||||||||||
| 37 | is => 'rw', | ||||||||||||||
| 38 | required => 0, | ||||||||||||||
| 39 | default => '', | ||||||||||||||
| 40 | ); | ||||||||||||||
| 41 | |||||||||||||||
| 42 | has 'is_valid' => ( | ||||||||||||||
| 43 | isa => 'Bool', | ||||||||||||||
| 44 | is => 'ro', | ||||||||||||||
| 45 | lazy => 1, | ||||||||||||||
| 46 | default => sub { | ||||||||||||||
| 47 | 3 | ▶ | my $self = shift; | ||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.2
| |||||||||||||||
| 48 | |||||||||||||||
| 49 | 3 | ▶ | return ( $self->source =~ m,^https?://.+, ) ? 1 : 0; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 50 | }, | ||||||||||||||
| 51 | 2 | ); | |||||||||||||
| 52 | |||||||||||||||
| 53 | 2 | has 'as_xml_gen' => ( | |||||||||||||
| 54 | isa => 'Object', | ||||||||||||||
| 55 | is => 'ro', | ||||||||||||||
| 56 | lazy => 1, | ||||||||||||||
| 57 | builder => '_build_as_xml_gen', | ||||||||||||||
| 58 | ); | ||||||||||||||
| 59 | |||||||||||||||
| 60 | sub _build_as_xml_gen { | ||||||||||||||
| 61 | 3 | ▶ | my $self = shift; | ||||||||||||
|
Subroutine
_build_as_xml_gen: called CC=11 SCAR=24.4
| |||||||||||||||
| 62 | |||||||||||||||
| 63 | 3 | my $gen = XML::Generator->new( ':pretty' ); | |||||||||||||
| 64 | |||||||||||||||
| 65 | 3 | my @comments_likes = (); | |||||||||||||
| 66 | 3 | ▶ | push( @comments_likes, 'fb:comments' ) if ( $self->enable_comments ); | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 67 | 3 | ▶ | push( @comments_likes, 'fb:likes' ) if ( $self->enable_likes ); | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 68 | |||||||||||||||
| 69 | 3 | my %attrs = (); | |||||||||||||
| 70 | |||||||||||||||
| 71 | 3 | ▶ | if ( @comments_likes ) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 72 | 1 | $attrs{'data-feedback'} = join( ' ', @comments_likes ); | |||||||||||||
| 73 | } | ||||||||||||||
| 74 | |||||||||||||||
| 75 | 3 | ▶ | if ( length $self->presentation ) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 76 | 1 | $attrs{'data-mode'} = $self->presentation; | |||||||||||||
| 77 | } | ||||||||||||||
| 78 | |||||||||||||||
| 79 | 3 | ▶ | if ( $self->isa('Facebook::InstantArticle::Figure::Image') ) { | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 80 | 2 | ▶ | return $gen->figure( | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 81 | ( keys %attrs ? \%attrs : undef ), | ||||||||||||||
| 82 | $gen->img( { src => $self->source } ), | ||||||||||||||
| 83 | ( length $self->caption ? $gen->figcaption(\$self->caption) : undef ), | ||||||||||||||
| 84 | ); | ||||||||||||||
| 85 | } | ||||||||||||||
| 86 | elsif ( $self->isa('Facebook::InstantArticle::Figure::Video') ) { | ||||||||||||||
| 87 | 1 | ▶ | return $gen->figure( | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 88 | ( keys %attrs ? \%attrs : undef ), | ||||||||||||||
| 89 | $gen->video( | ||||||||||||||
| 90 | $gen->source( { src => $self->source } ), | ||||||||||||||
| 91 | ), | ||||||||||||||
| 92 | ( length $self->caption ? $gen->figcaption(\$self->caption) : undef ), | ||||||||||||||
| 93 | ); | ||||||||||||||
| 94 | } | ||||||||||||||
| 95 | } | ||||||||||||||
| 96 | |||||||||||||||
| 97 | 2 | 1; | |||||||||||||