[Catalyst-commits] r10964 - in
Catalyst-Authentication-Credential-FBConnect/trunk: .
lib/Catalyst/Authentication/Credential
cosmincx at dev.catalyst.perl.org
cosmincx at dev.catalyst.perl.org
Thu Jul 23 14:30:51 GMT 2009
Author: cosmincx
Date: 2009-07-23 14:30:50 +0000 (Thu, 23 Jul 2009)
New Revision: 10964
Modified:
Catalyst-Authentication-Credential-FBConnect/trunk/Makefile.PL
Catalyst-Authentication-Credential-FBConnect/trunk/lib/Catalyst/Authentication/Credential/FBConnect.pm
Log:
merge cleanup-moose into trunk
Modified: Catalyst-Authentication-Credential-FBConnect/trunk/Makefile.PL
===================================================================
--- Catalyst-Authentication-Credential-FBConnect/trunk/Makefile.PL 2009-07-23 13:51:39 UTC (rev 10963)
+++ Catalyst-Authentication-Credential-FBConnect/trunk/Makefile.PL 2009-07-23 14:30:50 UTC (rev 10964)
@@ -3,6 +3,9 @@
name 'Catalyst-Authentication-Credential-FBConnect';
all_from 'lib/Catalyst/Authentication/Credential/FBConnect.pm';
+requires 'MooseX::Types';
+requires 'MooseX::Types::Common';
+requires 'namespace::autoclean';
requires 'WWW::Facebook::API';
requires 'Moose';
build_requires 'Catalyst::Runtime';
Modified: Catalyst-Authentication-Credential-FBConnect/trunk/lib/Catalyst/Authentication/Credential/FBConnect.pm
===================================================================
--- Catalyst-Authentication-Credential-FBConnect/trunk/lib/Catalyst/Authentication/Credential/FBConnect.pm 2009-07-23 13:51:39 UTC (rev 10963)
+++ Catalyst-Authentication-Credential-FBConnect/trunk/lib/Catalyst/Authentication/Credential/FBConnect.pm 2009-07-23 14:30:50 UTC (rev 10964)
@@ -1,47 +1,35 @@
package Catalyst::Authentication::Credential::FBConnect;
-use strict;
-use warnings;
-
-use Moose; # Moose gave you strict and warnings already
-
-# This _config thing just isn't needed.. It's a throwback in the code you've
-# cargo culted to the days when the auth credential used to be a plugin
-# on the app class :/
-has _config => ( is => 'rw' ); # Do these actually need to be rw??
-has debug => ( is => 'rw' );
-has key => ( is => 'rw' );
-has secret => ( is => 'rw' );
-has app_name => ( is => 'rw' );
-has fbconnect => ( is => 'rw' );
-
+use Moose;
+use MooseX::Types::Moose qw/ Bool /;
+use MooseX::Types::Common::String qw/ NonEmptySimpleStr /;
use WWW::Facebook::API;
use Catalyst::Exception ();
+use namespace::autoclean;
-sub new { # Writing your own ->new method makes Moose sad, implement BUILDARGS
- # and BUILD instead
+has debug => ( is => 'ro', isa => Bool, );
+has api_key => ( is => 'ro', isa => NonEmptySimpleStr, required => 1 );
+has secret => ( is => 'ro', isa => NonEmptySimpleStr, required => 1 );
+has app_name => ( is => 'ro', isa => NonEmptySimpleStr, required => 1 );
+has fbconnect => ( is => 'ro', lazy_build => 1, init_arg => undef, isa => 'WWW::Facebook::API' );
+
+sub BUILDARGS {
my ($class, $config, $c, $realm) = @_;
- my $self = { _config => {
- %{ $config },
- %{ $realm->{config} } # Ewww, gross hack to steal the realms config too.
- } };
+ return $config;
+}
- bless $self, $class;
+sub BUILD {
+ my ($self) = @_;
+ $self->fbconnect; # Ensure lazy value is built.
+}
- $self->debug( $self->_config->{debug} );
+sub _build_fbconnect {
+ my $self = shift;
- $self->key( $self->_config->{key} );
- $self->secret( $self->_config->{secret} );
- $self->app_name( $self->_config->{app_name} );
-
- $self->fbconnect( WWW::Facebook::API->new(
+ WWW::Facebook::API->new(
desktop => 0,
- app_name => $self->app_name,
- api_key => $self->key,
- secret => $self->secret
- ) );
-
- return $self;
+ map { $_ => $self->$_() } qw/ app_name api_key secret /
+ );
}
sub authenticate {
@@ -70,8 +58,7 @@
return;
}
else {
-
- $c->res->redirect( $self->fbconnect->get_login_url( next => $c->uri_for( $c->action ) ) );
+ $c->res->redirect( $self->fbconnect->get_login_url( next => $c->uri_for( $c->action, $c->req->captures, @{ $c->req->args } ) ) );
}
}
@@ -102,19 +89,19 @@
In myapp.conf
- <Plugin::Authentication>
- default_realm facebook
- <realms>
- <facebook>
+ <Plugin::Authentication>
+ default_realm facebook
+ <realms>
+ <facebook>
<credential>
- class FBConnect
- </credential>
- key my_app_key
- secret my_app_secret
- app_name my_app_name
- </facebook>
- </realms>
-</Plugin::Authentication>
+ class FBConnect
+ api_key my_app_key
+ secret my_app_secret
+ app_name my_app_name
+ </credential>
+ </facebook>
+ </realms>
+ </Plugin::Authentication>
In controller code,
More information about the Catalyst-commits
mailing list