From: Dave Rolsky Date: Tue, 6 Jan 2009 05:24:24 +0000 (+0000) Subject: Ran the sample code through perltidy X-Git-Tag: 0.65~35 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=8a7ed43e99ef868725a9de9f9de2e4b58af05ccb;p=gitmo%2FMoose.git Ran the sample code through perltidy --- diff --git a/lib/Moose/Cookbook/Basics/Recipe2.pod b/lib/Moose/Cookbook/Basics/Recipe2.pod index b42a03c..152ebd8 100644 --- a/lib/Moose/Cookbook/Basics/Recipe2.pod +++ b/lib/Moose/Cookbook/Basics/Recipe2.pod @@ -9,33 +9,33 @@ Moose::Cookbook::Basics::Recipe2 - A simple B example package BankAccount; use Moose; - - has 'balance' => (isa => 'Int', is => 'rw', default => 0); - + + has 'balance' => ( isa => 'Int', is => 'rw', default => 0 ); + sub deposit { - my ($self, $amount) = @_; - $self->balance($self->balance + $amount); + my ( $self, $amount ) = @_; + $self->balance( $self->balance + $amount ); } - + sub withdraw { - my ($self, $amount) = @_; + my ( $self, $amount ) = @_; my $current_balance = $self->balance(); - ($current_balance >= $amount) + ( $current_balance >= $amount ) || confess "Account overdrawn"; - $self->balance($current_balance - $amount); + $self->balance( $current_balance - $amount ); } - + package CheckingAccount; use Moose; - + extends 'BankAccount'; - - has 'overdraft_account' => (isa => 'BankAccount', is => 'rw'); - + + has 'overdraft_account' => ( isa => 'BankAccount', is => 'rw' ); + before 'withdraw' => sub { - my ($self, $amount) = @_; + my ( $self, $amount ) = @_; my $overdraft_amount = $amount - $self->balance(); - if ($self->overdraft_account && $overdraft_amount > 0) { + if ( $self->overdraft_account && $overdraft_amount > 0 ) { $self->overdraft_account->withdraw($overdraft_amount); $self->deposit($overdraft_amount); } @@ -65,7 +65,7 @@ account. (1) The first class, B, introduces a new attribute feature, a default value: - has 'balance' => (isa => 'Int', is => 'rw', default => 0); + has 'balance' => ( isa => 'Int', is => 'rw', default => 0 ); This says that a B has a C attribute, which has a C type constraint, a read/write accessor, and a default value @@ -81,7 +81,7 @@ class's superclass. Here we see that B C B. The next line introduces yet another new attribute feature, class-based type constraints: - has 'overdraft_account' => (isa => 'BankAccount', is => 'rw'); + has 'overdraft_account' => ( isa => 'BankAccount', is => 'rw' ); Up until now, we have only seen the C type constraint, which (as we saw in the first recipe) is a builtin type constraint. The @@ -101,9 +101,9 @@ In B, we see another method modifier, the C modifier. before 'withdraw' => sub { - my ($self, $amount) = @_; + my ( $self, $amount ) = @_; my $overdraft_amount = $amount - $self->balance(); - if ($self->overdraft_account && $overdraft_amount > 0) { + if ( $self->overdraft_account && $overdraft_amount > 0 ) { $self->overdraft_account->withdraw($overdraft_amount); $self->deposit($overdraft_amount); } @@ -124,9 +124,9 @@ As with the method modifier in the first recipe, we could use C to get the same effect: sub withdraw { - my ($self, $amount) = @_; + my ( $self, $amount ) = @_; my $overdraft_amount = $amount - $self->balance(); - if ($self->overdraft_account && $overdraft_amount > 0) { + if ( $self->overdraft_account && $overdraft_amount > 0 ) { $self->overdraft_account->withdraw($overdraft_amount); $self->deposit($overdraft_amount); }