Twitter/User.pm

filter: Statementstmt 100% 35 / 35 Branchbran 87.5% 7 / 8 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 5 / 5 Podpod 100% 1 / 1 totaltotal 97.9% 48 / 49 CC 5 SCAR 11.7
CC
5
Cov
98%
from_source
5.0
BEGIN
1.0
BEGIN
1.0
CRAP 3.2
« Twitter/Tweet.pm ↑ Summary Twitter/Media.pm »
1 package Mojo::WebService::Twitter::User;
2 2 ▶use Mojo::Base -base;
Subroutine BEGIN: called CC=1 SCAR=0.0
3  
4 2 ▶use Mojo::WebService::Twitter::Tweet;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use Mojo::WebService::Twitter::Util 'parse_twitter_timestamp';
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶use Scalar::Util 'weaken';
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 2 our $VERSION = '1.003';
9  
10 2 has [qw(source created_at description followers friends id last_tweet name
11 protected screen_name statuses time_zone url utc_offset verified)];
12  
13 42 ▶sub from_source {
Subroutine from_source: called CC=5 SCAR=16.1
Pod documented
14 42 my ($self, $source) = @_;
15 42 ▶ $self->created_at(parse_twitter_timestamp($source->{created_at})) if defined $source->{created_at};
Branch: 1 branch
BranchTrueFalseTotal
if defined $source->{"created_at"} 22 20 42
16 42 $self->description($source->{description});
17 42 $self->followers($source->{followers_count});
18 42 $self->friends($source->{friends_count});
19 42 $self->id($source->{id});
20 42 $self->name($source->{name});
21 42 ▶ $self->protected($source->{protected} ? 1 : 0);
Branch: 1 branch
BranchTrueFalseTotal
$source->{'protected'} ? : 0 42 42
22 42 $self->screen_name($source->{screen_name});
23 42 $self->statuses($source->{statuses_count});
24 42 $self->time_zone($source->{time_zone});
25 42 $self->url($source->{url});
26 42 $self->utc_offset($source->{utc_offset});
27 42 ▶ $self->verified($source->{verified} ? 1 : 0);
Branch: 1 branch
BranchTrueFalseTotal
$source->{'verified'} ? : 5 37 42
28 42 ▶ if (defined $source->{status}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $source->{"status"}) 2 40 42
29 2 my $tweet = Mojo::WebService::Twitter::Tweet->new->from_source($source->{status});
30 2 weaken($tweet->{user} = $self);
31 2 $self->last_tweet($tweet);
32 }
33 42 $self->source($source);
34 42 return $self;
35 }
36  
37 2 1;
38  
39 =head1 NAME
40  
41 Mojo::WebService::Twitter::User - A Twitter user
42  
43 =head1 SYNOPSIS
44  
45 use Mojo::WebService::Twitter;
46 my $twitter = Mojo::WebService::Twitter->new(api_key => $api_key, api_secret => $api_secret);
47 my $user = $twitter->get_user(user_id => $user_id);
48
49 my $username = $user->screen_name;
50 my $name = $user->name;
51 my $created_at = $user->created_at;
52 my $description = $user->description;
53 say "[$created_at] \@$username ($user): $description";
54  
55 =head1 DESCRIPTION
56  
57 L<Mojo::WebService::Twitter::User> is an object representing a
58 L<Twitter|https://twitter.com> user. See L<https://dev.twitter.com/overview/api/users>
59 for more information.
60  
61 =head1 ATTRIBUTES
62  
63 =head2 source
64  
65 my $href = $user->source;
66  
67 Source data hashref from Twitter API.
68  
69 =head2 created_at
70  
71 my $ts = $user->created_at;
72  
73 L<Time::Piece> object representing the creation time of the user in UTC.
74  
75 =head2 description
76  
77 my $description = $user->description;
78  
79 User's profile description.
80  
81 =head2 followers
82  
83 my $count = $user->followers;
84  
85 Number of followers of the user.
86  
87 =head2 friends
88  
89 my $count = $user->friends;
90  
91 Number of friends of the user.
92  
93 =head2 id
94  
95 my $user_id = $user->id;
96  
97 User identifier.
98  
99 =head2 last_tweet
100  
101 my $tweet = $user->last_tweet;
102  
103 Most recent tweet by the user (if any), as a L<Mojo::WebService::Twitter::Tweet>
104 object.
105  
106 =head2 name
107  
108 my $name = $user->name;
109  
110 User's full name.
111  
112 =head2 protected
113  
114 my $bool = $user->protected;
115  
116 Whether the user's tweets are protected.
117  
118 =head2 screen_name
119  
120 my $screen_name = $user->screen_name;
121  
122 User's twitter screen name.
123  
124 =head2 statuses
125  
126 my $count = $user->statuses;
127  
128 Number of tweets the user has sent.
129  
130 =head2 time_zone
131  
132 my $tz = $user->time_zone;
133  
134 String describing the user's time zone. This is now always undefined; see
135 L<https://twittercommunity.com/t/upcoming-changes-to-the-developer-platform/104603>.
136  
137 =head2 url
138  
139 my $url = $user->url;
140  
141 User's profile URL.
142  
143 =head2 utc_offset
144  
145 my $seconds = $user->utc_offset;
146  
147 User's current offset from UTC in seconds. This is now always undefined; see
148 L<https://twittercommunity.com/t/upcoming-changes-to-the-developer-platform/104603>.
149  
150 =head2 verified
151  
152 my $bool = $user->verified;
153  
154 Whether the user is a L<Verified Account|https://twitter.com/help/verified>.
155  
156 =head1 METHODS
157  
158 L<Mojo::WebService::Twitter::User> inherits all methods from L<Mojo::Base>, and
159 implements the following new ones.
160  
161 =head2 from_source
162  
163 $user = $user->from_source($hr);
164  
165 Populate attributes from hashref of Twitter API source data.
166  
167 =head1 BUGS
168  
169 Report any issues on the public bugtracker.
170  
171 =head1 AUTHOR
172  
173 Dan Book <dbook@cpan.org>
174  
175 =head1 COPYRIGHT AND LICENSE
176  
177 This software is Copyright (c) 2015 by Dan Book.
178  
179 This is free software, licensed under:
180  
181 The Artistic License 2.0 (GPL Compatible)
182  
183 =head1 SEE ALSO
184  
185 L<Mojo::WebService::Twitter>
« Twitter/Tweet.pm ↑ Summary Twitter/Media.pm »