Create an Account
username: password:
 
  MemeStreams Logo

MemeStreams Discussion

search


This page contains all of the posts and discussion on MemeStreams referencing the following web page: Moose - A postmodern object system for Perl 5 - search.cpan.org. You can find discussions on MemeStreams as you surf the web, even if you aren't a MemeStreams member, using the Threads Bookmarklet.

Moose - A postmodern object system for Perl 5 - search.cpan.org
by Lost at 2:25 am EST, Dec 23, 2008

Moose makes Perl5 objects not suck. It makes Perl fun again.

Look below. For one thing, I do not have to do a new() or Perl's silly hacked object shenanigans. Moose does that for me. If I want code to run at instantiation, I can make a BUILD() sub, but instead of doing that I can define properties of the object that save me from writing code.

For instance, look at $sdb. I initialize it to a default in the declaration, so I don't have to bind the variable in new(). $separator and $replace are required arguments (in a hash) and so they are declares as such. Moose will do the complaining for me if we don't get them.

I'm not usually an advocate of meta-code, but in this case the payoff is instant. Moose is great.

Ex:

package Amazon::SimpleDB::Simple;

use Moose;
use Carp;
use Amazon::SimpleDB::Client;

has 'sdb' => (
isa => 'Amazon::SimpleDB::Client',
is => 'rw',
lazy => 1,
default => sub {
my $self = shift;
Amazon::SimpleDB::Client->new($self->AWS_ACCESS_KEY_ID,
$self->AWS_SECRET_ACCESS_KEY);
}
);

has 'max' => (isa => 'Int', is => 'rw', default => 100);

has [qw/AWS_ACCESS_KEY_ID AWS_SECRET_ACCESS_KEY domain/] =>
(isa => 'Str', is => 'ro', required => 1);

has 'separator' => (isa => 'Str', is => 'rw', required => 1);

has 'replace' => (isa => 'Int', is => 'rw', required => 1);

sub put_attributes
{
my ($self, $item_name, @pairs) = @_;

my $response =
$self->sdb->putAttributes(
{
DomainName => $self->domain,
ItemName => $item_name,
Attribute => pairs_to_attributes(\@pairs, 1),
}
);
}


 
 
Powered By Industrial Memetics