From: Dave Rolsky Date: Tue, 6 Jan 2009 05:40:01 +0000 (+0000) Subject: tidy code in pod for consistency X-Git-Tag: 0.65~32 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=a39ea7dc7de7e673d896b4320da262478e4efe83;p=gitmo%2FMoose.git tidy code in pod for consistency --- diff --git a/lib/Moose/Cookbook/Roles/Recipe1.pod b/lib/Moose/Cookbook/Roles/Recipe1.pod index 82ae9fe..430b3f6 100644 --- a/lib/Moose/Cookbook/Roles/Recipe1.pod +++ b/lib/Moose/Cookbook/Roles/Recipe1.pod @@ -9,66 +9,66 @@ Moose::Cookbook::Roles::Recipe1 - The Moose::Role example package Eq; use Moose::Role; - + requires 'equal_to'; - - sub not_equal_to { - my ($self, $other) = @_; + + sub not_equal_to { + my ( $self, $other ) = @_; not $self->equal_to($other); } - + package Comparable; use Moose::Role; - + with 'Eq'; - + requires 'compare'; - + sub equal_to { - my ($self, $other) = @_; + my ( $self, $other ) = @_; $self->compare($other) == 0; - } - + } + sub greater_than { - my ($self, $other) = @_; + my ( $self, $other ) = @_; $self->compare($other) == 1; - } - + } + sub less_than { - my ($self, $other) = @_; + my ( $self, $other ) = @_; $self->compare($other) == -1; } - + sub greater_than_or_equal_to { - my ($self, $other) = @_; + my ( $self, $other ) = @_; $self->greater_than($other) || $self->equal_to($other); - } - + } + sub less_than_or_equal_to { - my ($self, $other) = @_; + my ( $self, $other ) = @_; $self->less_than($other) || $self->equal_to($other); - } - + } + package Printable; use Moose::Role; - - requires 'to_string'; - + + requires 'to_string'; + package US::Currency; use Moose; - + with 'Comparable', 'Printable'; - - has 'amount' => (is => 'rw', isa => 'Num', default => 0); - + + has 'amount' => ( is => 'rw', isa => 'Num', default => 0 ); + sub compare { - my ($self, $other) = @_; + my ( $self, $other ) = @_; $self->amount <=> $other->amount; } - + sub to_string { my $self = shift; - sprintf '$%0.2f USD' => $self->amount + sprintf '$%0.2f USD' => $self->amount; } =head1 DESCRIPTION @@ -119,27 +119,27 @@ defining a number of utility methods in terms of only a single method that the target class need implement. sub equal_to { - my ($self, $other) = @_; + my ( $self, $other ) = @_; $self->compare($other) == 0; } - + sub greater_than { - my ($self, $other) = @_; + my ( $self, $other ) = @_; $self->compare($other) == 1; - } - + } + sub less_than { - my ($self, $other) = @_; + my ( $self, $other ) = @_; $self->compare($other) == -1; } - + sub greater_than_or_equal_to { - my ($self, $other) = @_; + my ( $self, $other ) = @_; $self->greater_than($other) || $self->equal_to($other); - } - + } + sub less_than_or_equal_to { - my ($self, $other) = @_; + my ( $self, $other ) = @_; $self->less_than($other) || $self->equal_to($other); } @@ -160,12 +160,12 @@ shows: It also defines a regular Moose attribute, C, with a type constraint of C and a default of C<0>: - has 'amount' => (is => 'rw', isa => 'Num', default => 0); + has 'amount' => ( is => 'rw', isa => 'Num', default => 0 ); Now we come to the core of the class. First up, we define a C method: sub compare { - my ($self, $other) = @_; + my ( $self, $other ) = @_; $self->amount <=> $other->amount; } @@ -180,7 +180,7 @@ C attribute for display: sub to_string { my $self = shift; - sprintf '$%0.2f USD' => $self->amount + sprintf '$%0.2f USD' => $self->amount; } =head1 CONCLUSION @@ -213,4 +213,4 @@ L This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. -=cut +=cut diff --git a/lib/Moose/Cookbook/Roles/Recipe2.pod b/lib/Moose/Cookbook/Roles/Recipe2.pod index 63836b1..003b692 100644 --- a/lib/Moose/Cookbook/Roles/Recipe2.pod +++ b/lib/Moose/Cookbook/Roles/Recipe2.pod @@ -25,8 +25,12 @@ Moose::Cookbook::Roles::Recipe2 - Advanced Role Composition - method exclusion a package Restartable::ButUnreliable; use Moose::Role; - with 'Restartable' => { alias => { stop => '_stop', - start => '_start' } }; + with 'Restartable' => { + alias => { + stop => '_stop', + start => '_start' + } + }; sub stop { my $self = shift;