X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-Authentication-Credential-FBConnect.git;a=blobdiff_plain;f=lib%2FCatalyst%2FAuthentication%2FCredential%2FFBConnect.pm;fp=lib%2FCatalyst%2FAuthentication%2FCredential%2FFBConnect.pm;h=bada55e4cb12c066f56bec40d75ad4f84c623b00;hp=869d4669deef3d3f69f45c0a3bf35e44d29e040a;hb=b73effaf981abc07900da74b6dcd8ddda2699f72;hpb=5c5e442dd6a40b98b0462df2c71eba85c61c3f9c diff --git a/lib/Catalyst/Authentication/Credential/FBConnect.pm b/lib/Catalyst/Authentication/Credential/FBConnect.pm index 869d466..bada55e 100644 --- a/lib/Catalyst/Authentication/Credential/FBConnect.pm +++ b/lib/Catalyst/Authentication/Credential/FBConnect.pm @@ -1,47 +1,39 @@ package Catalyst::Authentication::Credential::FBConnect; -use strict; -use warnings; +use Moose; +use namespace::autoclean; -use Moose; # Moose gave you strict and warnings already +has debug => ( is => 'ro' ); +has key => ( is => 'ro' ); +has secret => ( is => 'ro' ); +has app_name => ( is => 'ro' ); +has fbconnect => ( is => 'ro', lazy_build => 1, init_arg => undef ); -# 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' ); +has realm => ( is => 'ro', required => 1, weak_ref => 1 ); use WWW::Facebook::API; use Catalyst::Exception (); -sub new { # Writing your own ->new method makes Moose sad, implement BUILDARGS - # and BUILD instead +sub BUILDARGS { my ($class, $config, $c, $realm) = @_; - my $self = { _config => { - %{ $config }, - %{ $realm->{config} } # Ewww, gross hack to steal the realms config too. - } }; - - bless $self, $class; - - $self->debug( $self->_config->{debug} ); + return { + %{ $config }, + %{ $realm->{config} }, # Ewww, gross hack to steal the realms config too. + realm => $realm, + }; +} - $self->key( $self->_config->{key} ); - $self->secret( $self->_config->{secret} ); - $self->app_name( $self->_config->{app_name} ); +sub BUILD { + my ($self) = @_; + $self->fbconnect; # Ensure lazy value is built. +} - $self->fbconnect( WWW::Facebook::API->new( +sub _build_fbconnect { + my $self = shift; + 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 {