blib/lib/Catalyst/Plugin/Facebook.pm

filter: Statementstmt 77.7% 7 / 9 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 3 / 3 Podpod n/a totaltotal 83.3% 10 / 12 CC 1 SCAR 0.9
CC
1
Cov
78%
BEGIN
1.3
BEGIN
1.0
BEGIN
1.0
CRAP 1.1
↑ Summary
1 package Catalyst::Plugin::Facebook;
2 our $VERSION = '0.2';
3  
4  
5 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 0 ▶use WWW::Facebook::API;
Subroutine BEGIN: called CC=1 SCAR=2.6
9  
10 use Scalar::Util qw();
11  
12 # why not
13 *fb = \&facebook;
14  
15 sub facebook {
16 my ($c) = @_;
17 unless ( $c->{'facebook'} and Scalar::Util::blessed($c->{'facebook'}) and $c->{'facebook'}->isa('WWW::Facebook::API') ) {
18 $c->{'facebook'} = WWW::Facebook::API->new(
19 'desktop' => 0,
20 'format' => 'JSON',
21 'parse' => 1,
22 %{ $c->config->{'facebook'} || { } },
23 );
24 $c->{'facebook'}->query( $c->request);
25 my $params = $c->facebook->canvas->get_fb_params;
26 $c->{'facebook'}->session('uid' => $params->{'user'}, 'key' => $params->{'session_key'}, 'expires' => $params->{'expires'});
27 }
28 return $c->{'facebook'};
29 }
30  
31 1;
32  
33  
34  
35 =pod
36  
37 =head1 VERSION
38  
39 version 0.2
40  
41 =pod
42  
43 =head1 NAME
44  
45 Catalyst::Plugin::Facebook - Build Facebook applications in Catalyst easier
46  
47 =head1 SYNOPSIS
48  
49 This module adds quick and easy access to WWW::Facebook::API within
50 a Catalyst application.
51  
52 use Catalyst qw/Facebook/;
53 __PACKAGE__->config(
54 'facebook' => {
55 'api_key' => 'api_key_xyz',
56 'secret' => '12345ddd',
57 }
58 );
59  
60 sub auto : Private {
61 my ( $self, $c ) = @_;
62 if (! $self->can_display($c)) {
63 return;
64 }
65 return 1;
66 }
67  
68 sub can_display {
69 my ($self, $c) = @_;
70 if (! $c->facebook->canvas->in_fb_canvas()) {
71 $c->res->redirect('http://apps.facebook.com/iplaywow/');
72 return 0;
73 }
74 if (! $c->facebook->canvas->get_fb_params->{'added'} ) {
75 $c->res->redirect($c->facebook->get_add_url());
76 return 0;
77 }
78 my $user = $c->facebook->canvas->get_fb_params->{'user'};
79 if (! $user) {
80 $c->res->redirect($c->facebook->get_login_url());
81 return 0;
82 }
83 return 1;
84 }
85  
86 =head1 CONFIGURATION
87  
88 This package uses the 'facebook' configuration namespace. See the
89 WWW::Facebook::API module for all of the configuration options available.
90  
91 The two required configuration options are 'api_key' and 'secret'.
92  
93 =head1 INTERFACE
94  
95 =head2 METHODS
96  
97 =head3 facebook
98  
99 This method, which will be available on your Catalyst context object, will
100 return the full L<WWW::Facebook::API> object.
101  
102 =head3 fb
103  
104 fb is just an alias for facebook.
105  
106 =head1 BUGS
107  
108 Please report any bugs or feature requests to
109 C<bug-catalyst-plugin-facebook at rt.cpan.org>, or through the web interface at
110 L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Catalyst-Plugin-Facebook>.
111 I will be notified, and then you'll automatically be notified of progress on
112 your bug as I make changes.
113  
114 =head1 SUPPORT
115  
116 You can find documentation for this module with the perldoc command.
117  
118 perldoc Catalyst::Plugin::Facebook
119  
120 You can also look for information at:
121  
122 =over 4
123  
124 =item * AnnoCPAN: Annotated CPAN documentation
125  
126 L<http://annocpan.org/dist/Catalyst-Plugin-Facebook>
127  
128 =item * CPAN Ratings
129  
130 L<http://cpanratings.perl.org/d/Catalyst-Plugin-Facebook>
131  
132 =item * RT: CPAN's request tracker
133  
134 L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Catalyst-Plugin-Facebook>
135  
136 =item * Search CPAN
137  
138 L<http://search.cpan.org/dist/Catalyst-Plugin-Facebook>
139  
140 =back
141  
142 =head1 COPYRIGHT & LICENSE
143  
144 Copyright 2007 Nick Gerakines, all rights reserved.
145  
146 This program is free software; you can redistribute it and/or modify it
147 under the same terms as Perl itself.
148  
149  
150  
151 =head1 AUTHOR
152  
153 Nick Gerakines <nick@gerakines.net>
154  
155 =head1 COPYRIGHT AND LICENSE
156  
157 This software is copyright (c) 2009 by Nick Gerakines.
158  
159 This is free software; you can redistribute it and/or modify it under
160 the same terms as the Perl 5 programming language system itself.
161  
162 =cut
163  
164  
165  
166 __END__
↑ Summary