From: Tomas Doran Date: Thu, 23 Jul 2009 00:15:53 +0000 (+0000) Subject: Big cleanup to make more Moose like code, make things read only etc X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-Authentication-Credential-FBConnect.git;a=commitdiff_plain;h=b73effaf981abc07900da74b6dcd8ddda2699f72 Big cleanup to make more Moose like code, make things read only etc --- diff --git a/Makefile.PL b/Makefile.PL index f17381b..5e04a94 100644 --- a/Makefile.PL +++ b/Makefile.PL @@ -3,6 +3,7 @@ use inc::Module::Install; name 'Catalyst-Authentication-Credential-FBConnect'; all_from 'lib/Catalyst/Authentication/Credential/FBConnect.pm'; +requires 'namespace::autoclean'; requires 'WWW::Facebook::API'; requires 'Moose'; build_requires 'Catalyst::Runtime'; 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 {