[Catalyst-commits] r10958 - in Catalyst-Authentication-Credential-FBConnect/branches/cleanup-moose: . lib/Catalyst/Authentication/Credential

t0m at dev.catalyst.perl.org t0m at dev.catalyst.perl.org
Thu Jul 23 00:15:54 GMT 2009


Author: t0m
Date: 2009-07-23 00:15:53 +0000 (Thu, 23 Jul 2009)
New Revision: 10958

Modified:
   Catalyst-Authentication-Credential-FBConnect/branches/cleanup-moose/Makefile.PL
   Catalyst-Authentication-Credential-FBConnect/branches/cleanup-moose/lib/Catalyst/Authentication/Credential/FBConnect.pm
Log:
Big cleanup to make more Moose like code, make things read only etc

Modified: Catalyst-Authentication-Credential-FBConnect/branches/cleanup-moose/Makefile.PL
===================================================================
--- Catalyst-Authentication-Credential-FBConnect/branches/cleanup-moose/Makefile.PL	2009-07-23 00:04:11 UTC (rev 10957)
+++ Catalyst-Authentication-Credential-FBConnect/branches/cleanup-moose/Makefile.PL	2009-07-23 00:15:53 UTC (rev 10958)
@@ -3,6 +3,7 @@
 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';

Modified: Catalyst-Authentication-Credential-FBConnect/branches/cleanup-moose/lib/Catalyst/Authentication/Credential/FBConnect.pm
===================================================================
--- Catalyst-Authentication-Credential-FBConnect/branches/cleanup-moose/lib/Catalyst/Authentication/Credential/FBConnect.pm	2009-07-23 00:04:11 UTC (rev 10957)
+++ Catalyst-Authentication-Credential-FBConnect/branches/cleanup-moose/lib/Catalyst/Authentication/Credential/FBConnect.pm	2009-07-23 00:15:53 UTC (rev 10958)
@@ -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.
-	} };
+    return {
+        %{ $config },
+        %{ $realm->{config} }, # Ewww, gross hack to steal the realms config too.
+        realm => $realm,
+    };
+}
 
-	bless $self, $class;
+sub BUILD {
+    my ($self) = @_;
+    $self->fbconnect; # Ensure lazy value is built.
+}
 
-	$self->debug( $self->_config->{debug} );
-
-	$self->key( $self->_config->{key} );
-	$self->secret( $self->_config->{secret} );
-	$self->app_name( $self->_config->{app_name} );
-
-	$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 {




More information about the Catalyst-commits mailing list