From: Marco Fontani Date: Sat, 20 Nov 2010 19:10:45 +0000 (+0000) Subject: Lazy attribute works X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=189564ce3d11c6702de3f0ec72a30ad852186cd4;p=p5sagit%2FOyster.git Lazy attribute works --- diff --git a/lib/Oyster/Provision/Rackspace.pm b/lib/Oyster/Provision/Rackspace.pm index 66d9ade..fff8bcd 100644 --- a/lib/Oyster/Provision/Rackspace.pm +++ b/lib/Oyster/Provision/Rackspace.pm @@ -7,15 +7,17 @@ use MIME::Base64; requires 'config'; -has 'api_username' => ( is => 'ro', isa => 'Str', required => 1, default => sub { +has 'api_username' => ( is => 'ro', isa => 'Str', required => 1, lazy_build => 1); +sub _build_api_username { return $ENV{CLOUDSERVERS_USER} if exists $ENV{CLOUDSERVERS_USER}; confess "Need api_username or CLOUDSERVERS_USER in environment"; }); -has 'api_password' => ( is => 'ro', isa => 'Str', required => 1, default => sub { +has 'api_password' => ( is => 'ro', isa => 'Str', required => 1, lazy_build => 1); +sub _build_api_password { return $ENV{CLOUDSERVERS_KEY} if exists $ENV{CLOUDSERVERS_KEY}; confess "Need api_password or CLOUDSERVERS_KEY in environment"; -}); +} has '_rs' => ( is => 'rw', isa => 'Net::RackSpace::CloudServers', default => sub { my $self = shift;