Skip to content

Commit

Permalink
reduce method calls
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Jan 30, 2014
1 parent a3ba3f3 commit 81c398b
Show file tree
Hide file tree
Showing 7 changed files with 10 additions and 17 deletions.
5 changes: 1 addition & 4 deletions lib/Mojo/Date.pm
Expand Up @@ -11,14 +11,11 @@ my @MONTHS = qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec);
my %MONTHS;
@MONTHS{@MONTHS} = (0 .. 11);

sub new { shift->SUPER::new->parse(@_) }
sub new { @_ > 1 ? shift->SUPER::new->parse(@_) : shift->SUPER::new }

sub parse {
my ($self, $date) = @_;

# Invalid
return $self unless defined $date;

# epoch (784111777)
return $self->epoch($date) if $date =~ /^\d+$/;

Expand Down
7 changes: 2 additions & 5 deletions lib/Mojo/Home.pm
Expand Up @@ -60,12 +60,9 @@ sub list_files {

sub mojo_lib_dir { catdir(dirname(__FILE__), '..') }

sub new { shift->SUPER::new->parse(@_) }
sub new { @_ > 1 ? shift->SUPER::new->parse(@_) : shift->SUPER::new }

sub parse {
my ($self, $path) = @_;
return defined $path ? $self->parts([splitdir $path]) : $self;
}
sub parse { shift->parts([splitdir shift]) }

sub rel_dir { catdir(@{shift->parts}, split '/', shift) }
sub rel_file { catfile(@{shift->parts}, split '/', shift) }
Expand Down
4 changes: 2 additions & 2 deletions lib/Mojo/Parameters.pm
Expand Up @@ -44,7 +44,7 @@ sub merge {
return $self;
}

sub new { shift->SUPER::new->parse(@_) }
sub new { @_ > 1 ? shift->SUPER::new->parse(@_) : shift->SUPER::new }

sub param {
my ($self, $name) = (shift, shift);
Expand Down Expand Up @@ -109,7 +109,7 @@ sub parse {
if (@_ > 1) { $self->append(@_) }

# String
else { $self->{string} = $_[0] }
else { $self->{string} = shift }

return $self;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/Mojo/Path.pm
Expand Up @@ -62,7 +62,7 @@ sub merge {
return $self->trailing_slash($path->trailing_slash);
}

sub new { shift->SUPER::new->parse(@_) }
sub new { @_ > 1 ? shift->SUPER::new->parse(@_) : shift->SUPER::new }

sub parse {
my $self = shift;
Expand Down
3 changes: 1 addition & 2 deletions lib/Mojo/URL.pm
Expand Up @@ -71,11 +71,10 @@ sub ihost {

sub is_abs { !!shift->scheme }

sub new { shift->SUPER::new->parse(@_) }
sub new { @_ > 1 ? shift->SUPER::new->parse(@_) : shift->SUPER::new }

sub parse {
my ($self, $url) = @_;
return $self unless $url;

# Official regex from RFC 3986
$url =~ m!^(([^:/?#]+):)?(//([^/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?!;
Expand Down
2 changes: 1 addition & 1 deletion lib/Mojolicious/Routes/Pattern.pm
Expand Up @@ -45,7 +45,7 @@ sub match_partial {
return $captures;
}

sub new { shift->SUPER::new->parse(@_) }
sub new { @_ > 1 ? shift->SUPER::new->parse(@_) : shift->SUPER::new }

sub parse {
my $self = shift;
Expand Down
4 changes: 2 additions & 2 deletions lib/Mojolicious/Routes/Route.pm
Expand Up @@ -426,8 +426,8 @@ the current route.
my $r = Mojolicious::Routes::Route->new;
my $r = Mojolicious::Routes::Route->new('/:controller/:action');
Construct a new L<Mojolicious::Routes::Route> object and <parse> pattern if
necessary.
Construct a new L<Mojolicious::Routes::Route> object and L</"parse"> pattern
if necessary.
=head2 options
Expand Down

0 comments on commit 81c398b

Please sign in to comment.