Twitter/Media.pm

filter: Statementstmt 94.7% 18 / 19 Branchbran 100% 2 / 2 Conditioncond 66.6% 2 / 3 MC/DCmcdc 50.0% 1 / 2 Subroutinesub 66.6% 2 / 3 Podpod 100% 1 / 1 totaltotal 86.6% 26 / 30 CC 3 SCAR 8.0
CC
3
Cov
92%
from_source
3.0
__ANON__
1.1
BEGIN
1.0
CRAP 2.2
« Twitter/User.pm ↑ Summary Twitter/Util.pm »
1 package Mojo::WebService::Twitter::Media;
2 2 ▶use Mojo::Base -base;
Subroutine BEGIN: called CC=1 SCAR=0.0
3  
4 2 our $VERSION = '1.003';
5  
6 2 has [qw(source display_url expanded_url id media_url source_status_id tweet type url)];
7 0 ▶has variants => sub { [] };
Subroutine __ANON__: not called CC=1 SCAR=1.2
8  
9 13 ▶sub from_source {
Subroutine from_source: called CC=3 SCAR=11.0
Pod documented
10 13 my ($self, $source) = @_;
11 13 $self->display_url($source->{display_url});
12 13 $self->expanded_url($source->{expanded_url});
13 13 $self->id($source->{id_str});
14 13 $self->media_url($source->{media_url_https});
15 13 $self->source_status_id($source->{source_status_id_str});
16 13 $self->type($source->{type});
17 13 $self->url($source->{url});
18 $self->variants($source->{video_info}{variants})
19 13 ▶ if defined $source->{video_info} and defined $source->{video_info}{variants};
Branch: 1 branch
BranchTrueFalseTotal
if defined $source->{"video_info"} and defined $source->{"video_info"}{"variants"} 9 4 13
Condition66%2/3
defined $source->{"video_info"} and defined $source->{"video_info"}{"variants"}
!ll&&!rl&&r
409
MC/DC50%1/2
defined $source->{"video_info"} and defined $source->{"video_info"}{"variants"}
defined $source->{"video_info"} defined $source->{"video_info"}{"variants"}
Truth table66%2/3
A and B
A= defined $source->{"video_info"}B= defined $source->{"video_info"}{"variants"}
ABresult
0X0
100
111
20 13 $self->source($source);
21 13 return $self;
22 }
23  
24 2 1;
25  
26 =head1 NAME
27  
28 Mojo::WebService::Twitter::Media - Media associated with a tweet
29  
30 =head1 SYNOPSIS
31  
32 use Mojo::WebService::Twitter;
33 my $twitter = Mojo::WebService::Twitter->new(api_key => $api_key, api_secret => $api_secret);
34 my $tweet = $twitter->get_tweet($tweet_id);
35  
36 my $media = $tweet->media;
37 foreach my $item (@$media) {
38 my $media_type = $item->type;
39 my $media_url = $item->media_url;
40 say "Media ($media_type): $media_url";
41 }
42  
43 =head1 DESCRIPTION
44  
45 L<Mojo::WebService::Twitter::Media> is an object representing native media
46 associated with a L<Twitter|https://twitter.com> tweet. See
47 L<https://developer.twitter.com/en/docs/tweets/data-dictionary/overview/extended-entities-object>
48 for more information.
49  
50 =head1 ATTRIBUTES
51  
52 =head2 source
53  
54 my $href = $media->source;
55  
56 Source data hashref from Twitter API.
57  
58 =head2 display_url
59  
60 my $url = $media->display_url;
61  
62 URL of the media for display purposes.
63  
64 =head2 expanded_url
65  
66 my $url = $media->expanded_url;
67  
68 Expanded version of L</"display_url">.
69  
70 =head2 id
71  
72 my $media_id = $media->id;
73  
74 Media identifier. Note that media IDs are usually too large to be represented
75 as a number, so should always be treated as a string.
76  
77 =head2 media_url
78  
79 my $url = $media->media_url;
80  
81 Direct URL to media of L</"type"> C<photo>, or a static thumbnail for media of
82 type C<video> or C<animated_gif>. Direct access to these types of media may be
83 found in L</"variants">.
84  
85 =head2 source_status_id
86  
87 my $tweet_id = $media->source_status_id;
88  
89 Tweet ID which media was originally associated with, or C<undef> if media was
90 originally associated with the current tweet.
91  
92 =head2 type
93  
94 my $type = $media->type;
95  
96 Media type, one of C<photo>, C<video>, or C<animated_gif>.
97  
98 =head2 tweet
99  
100 my $tweet = $media->tweet;
101  
102 Tweet in which the media is contained, as a L<Mojo::WebService::Twitter::Tweet>
103 object.
104  
105 =head2 variants
106  
107 my $variants = $media->variants;
108  
109 Array reference of variant hashrefs for media of L</"type"> C<video> or
110 C<animated_gif>, with keys C<content_type>, C<url>, and possibly C<bitrate>,
111 representing direct access to the media if available.
112  
113 =head1 METHODS
114  
115 L<Mojo::WebService::Twitter::Media> inherits all methods from L<Mojo::Base>,
116 and implements the following new ones.
117  
118 =head2 from_source
119  
120 $media = $media->from_source($hr);
121  
122 Populate attributes from hashref of Twitter API source data.
123  
124 =head1 BUGS
125  
126 Report any issues on the public bugtracker.
127  
128 =head1 AUTHOR
129  
130 Dan Book <dbook@cpan.org>
131  
132 =head1 COPYRIGHT AND LICENSE
133  
134 This software is Copyright (c) 2015 by Dan Book.
135  
136 This is free software, licensed under:
137  
138 The Artistic License 2.0 (GPL Compatible)
139  
140 =head1 SEE ALSO
141  
142 L<Mojo::WebService::Twitter>
« Twitter/User.pm ↑ Summary Twitter/Util.pm »