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;h=6d549ef514bbff01cba018e6e2a3e3b9b53c639e;hp=869d4669deef3d3f69f45c0a3bf35e44d29e040a;hb=b42cdcea556e5ba06e1024c64f560823affcf8d9;hpb=5c5e442dd6a40b98b0462df2c71eba85c61c3f9c diff --git a/lib/Catalyst/Authentication/Credential/FBConnect.pm b/lib/Catalyst/Authentication/Credential/FBConnect.pm index 869d466..6d549ef 100644 --- a/lib/Catalyst/Authentication/Credential/FBConnect.pm +++ b/lib/Catalyst/Authentication/Credential/FBConnect.pm @@ -1,47 +1,34 @@ 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 - my ($class, $config, $c, $realm) = @_; - - my $self = { _config => { - %{ $config }, - %{ $realm->{config} } # Ewww, gross hack to steal the realms config too. - } }; +has debug => ( is => 'ro', isa => Bool, ); +has 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' ); - bless $self, $class; +sub BUILDARGS { + my ($class, $config, $c, $realm) = @_; - $self->debug( $self->_config->{debug} ); + return $config; +} - $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 {