File Coverage

blib/lib/Facebook/Graph/Picture.pm
Criterion Covered Total %
statement 20 20 100.0
branch 2 2 100.0
condition n/a
subroutine 5 5 100.0
pod 4 4 100.0
total 31 31 100.0


line stmt bran cond sub pod time code
1             package Facebook::Graph::Picture;
2             $Facebook::Graph::Picture::VERSION = '1.1204';
3 4     4   26 use Moo;
  4         7  
  4         24  
4             with 'Facebook::Graph::Role::Uri';
5              
6             has type => (
7             is => 'rw',
8             predicate => 'has_type',
9             );
10              
11             has object_name => (
12             is => 'rw',
13             default => sub {''},
14             );
15              
16             sub get_small {
17 1     1 1 869 my ($self) = @_;
18 1         8 $self->type('small');
19 1         6 return $self;
20             }
21              
22             sub get_square {
23 1     1 1 823 my ($self) = @_;
24 1         9 $self->type('square');
25 1         5 return $self;
26             }
27              
28             sub get_large {
29 1     1 1 837 my ($self) = @_;
30 1         10 $self->type('large');
31 1         5 return $self;
32             }
33              
34             sub uri_as_string {
35 4     4 1 1870 my ($self) = @_;
36 4         15 my %query;
37 4 100       29 if ($self->has_type) {
38 3         14 $query{type} = $self->type;
39             }
40 4         30 my $uri = $self->uri;
41 4         6735 $uri->path($self->generate_versioned_path($self->object_name . '/picture'));
42 4         323 $uri->query_form(%query);
43 4         346 return $uri->as_string;
44             }
45              
46              
47             1;
48              
49             =head1 NAME
50              
51             Facebook::Graph::Picture - Get the URI for the picture of any object.
52              
53             =head1 VERSION
54              
55             version 1.1204
56              
57             =head1 SYNOPSIS
58              
59             my $fb = Facebook::Graph->new;
60            
61             my $default_picture = $fb->picture('16665510298')->uri_as_string;
62             my $large_picture = $fb->picture('16665510298')->get_large->uri_as_string;
63             my $small_picture = $fb->picture('16665510298')->get_small->uri_as_string;
64             my $square_picture = $fb->picture('16665510298')->get_square->uri_as_string;
65              
66             =head1 DESCRIPTION
67              
68             This module allows you to generate the URL needed to fetch a picture for any object on Facebook.
69              
70             =head1 METHODS
71              
72             =head2 new ( [ params ] )
73              
74             =over
75              
76             =item params
77              
78             A hash or hashref of parameters to pass to the constructor.
79              
80             =over
81              
82             =item object_name
83              
84             An profile id like C<sarahbownds> or an object id like C<16665510298> for the Perl page.
85              
86             =item type
87              
88             Type of picture to return. Valid types are small, square, large
89              
90             =back
91              
92             =back
93              
94             =head2 get_large ( id )
95              
96             Get a large picture. 200 pixels wide by a variable height.
97              
98             =head3 id
99              
100             The unique id or object name of an object.
101              
102             B<Example:> For user "Sarah Bownds" you could use either her profile id C<sarahbownds> or her object id C<767598108>.
103              
104              
105             =head2 get_small ( id )
106              
107             Get a small picture. 50 pixels wide by a variable height.
108              
109             =head3 id
110              
111             The unique id or object name of an object.
112              
113             B<Example:> For user "Sarah Bownds" you could use either her profile id C<sarahbownds> or her object id C<767598108>.
114              
115              
116             =head2 get_square ( id )
117              
118             Get a square picture. 50 pixels wide by 50 pixels tall.
119              
120             =head3 id
121              
122             The unique id or object name of an object.
123              
124             B<Example:> For user "Sarah Bownds" you could use either her profile id C<sarahbownds> or her object id C<767598108>.
125              
126              
127              
128              
129             =head2 uri_as_string ()
130              
131             Returns a URI string based upon all the methods you've called so far on the query. You can throw the resulting URI right into an <img> tag.
132              
133              
134             =head1 LEGAL
135              
136             Facebook::Graph is Copyright 2010 - 2012 Plain Black Corporation (L<http://www.plainblack.com>) and is licensed under the same terms as Perl itself.
137              
138             =cut