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 {