Skip to content

Commit

Permalink
small optimizations
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed May 27, 2012
1 parent d3604e6 commit 3d8a28f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 19 deletions.
15 changes: 5 additions & 10 deletions lib/Mojo/ByteStream.pm
@@ -1,10 +1,12 @@
package Mojo::ByteStream;
use Mojo::Base -strict;
use Mojo::Base 'Exporter';
use overload '""' => sub { shift->to_string }, fallback => 1;

use Mojo::Collection;
use Mojo::Util;

our @EXPORT_OK = ('b');

# Turn most functions from Mojo::Util into methods
my @UTILS = (
qw(b64_decode b64_encode camelize decamelize hmac_md5_sum hmac_sha1_sum),
Expand All @@ -24,22 +26,15 @@ my @UTILS = (
}
}

sub import {
my $class = shift;
return unless @_ > 0;
no strict 'refs';
no warnings 'redefine';
my $caller = caller;
*{"${caller}::b"} = sub { $class->new(@_) };
}

# "Do we have any food that wasn't brutally slaughtered?
# Well, I think the veal died of loneliness."
sub new {
my $class = shift;
return bless \(my $dummy = join '', @_), ref $class || $class;
}

sub b { __PACKAGE__->new(@_) }

sub clone {
my $self = shift;
return $self->new($$self);
Expand Down
13 changes: 4 additions & 9 deletions lib/Mojo/Collection.pm
@@ -1,5 +1,5 @@
package Mojo::Collection;
use Mojo::Base -strict;
use Mojo::Base 'Exporter';
use overload
'bool' => sub {1},
'""' => sub { shift->join("\n") },
Expand All @@ -8,20 +8,15 @@ use overload
use List::Util;
use Mojo::ByteStream;

sub import {
my $class = shift;
return unless @_ > 0;
no strict 'refs';
no warnings 'redefine';
my $caller = caller;
*{"${caller}::c"} = sub { $class->new(@_) };
}
our @EXPORT_OK = ('c');

sub new {
my $class = shift;
return bless [@_], ref $class || $class;
}

sub c { __PACKAGE__->new(@_) }

sub each {
my ($self, $cb) = @_;
return @$self unless $cb;
Expand Down

0 comments on commit 3d8a28f

Please sign in to comment.