Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
better Mojo::Base example
  • Loading branch information
kraih committed Sep 3, 2012
1 parent e23ffcd commit 57a3cae
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 14 deletions.
2 changes: 1 addition & 1 deletion Changes
@@ -1,5 +1,5 @@

3.37 2012-09-03
3.37 2012-09-04
- Added finish method to Mojo::Message.
- Updated jQuery to version 1.8.1.
- Improved documentation.
Expand Down
4 changes: 2 additions & 2 deletions lib/Mojo/Asset/Memory.pm
Expand Up @@ -45,8 +45,8 @@ sub get_chunk {
}

sub move_to {
my ($self, $path) = @_;
return $self->tap(sub { spurt $_->{content}, $path });
my ($self, $to) = @_;
return $self->tap(sub { spurt $_->{content}, $to });
}

sub size { length shift->{content} }
Expand Down
8 changes: 4 additions & 4 deletions lib/Mojo/Base.pm
Expand Up @@ -116,7 +116,7 @@ Mojo::Base - Minimal base class for Mojo projects
use Mojo::Base -base;
has name => 'Nyan';
has [qw(ears eyes)] => 2;
has [qw(birds mice)] => 2;
package Tiger;
use Mojo::Base 'Cat';
Expand All @@ -128,11 +128,11 @@ Mojo::Base - Minimal base class for Mojo projects
use Mojo::Base -strict;
my $mew = Cat->new(name => 'Longcat');
say $mew->ears;
say $mew->ears(3)->eyes(4)->ears;
say $mew->mice;
say $mew->mice(3)->birds(4)->mice;
my $rawr = Tiger->new(stripes => 23);
say $rawr->tap(sub { $_->friend->name('Tacgnol') })->ears;
say $rawr->tap(sub { $_->friend->name('Tacgnol') })->mice;
=head1 DESCRIPTION
Expand Down
8 changes: 4 additions & 4 deletions lib/Mojo/ByteStream.pm
Expand Up @@ -39,13 +39,13 @@ sub clone {
}

sub decode {
my ($self, $enc) = @_;
return $self->tap(sub { $$_ = Mojo::Util::decode $enc || 'UTF-8', $$_ });
my ($self, $e) = @_;
return $self->tap(sub { $$_ = Mojo::Util::decode $e || 'UTF-8', $$_ });
}

sub encode {
my ($self, $enc) = @_;
return $self->tap(sub { $$_ = Mojo::Util::encode $enc || 'UTF-8', $$_ });
my ($self, $e) = @_;
return $self->tap(sub { $$_ = Mojo::Util::encode $e || 'UTF-8', $$_ });
}

sub say {
Expand Down
2 changes: 0 additions & 2 deletions lib/Mojolicious/Routes/Route.pm
Expand Up @@ -88,8 +88,6 @@ sub is_websocket { !!shift->{websocket} }

sub name {
my $self = shift;

# Custom names have precedence
return $self->{name} unless @_;
$self->{name} = shift;
return $self->tap(sub { $_->{custom} = 1 });
Expand Down
3 changes: 2 additions & 1 deletion lib/Mojolicious/Types.pm
Expand Up @@ -52,7 +52,8 @@ sub type {
my ($self, $ext, $type) = @_;
my $types = $self->types;
return ref $types->{$ext} ? $types->{$ext}[0] : $types->{$ext} unless $type;
return $self->tap(sub { $types->{$ext} = $type });
$types->{$ext} = $type;
return $self;
}

1;
Expand Down

0 comments on commit 57a3cae

Please sign in to comment.