Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

only load commands if used #2

Merged
merged 1 commit into from

2 participants

@yanick

this should make things much more zippy if we have more than a handful of commands.

@yanick yanick don't load commands unless they are used
this should make things much more zippy if we have
more than a handful of commands.
54be2bf
@Getty Getty merged commit 03139b6 into Getty:master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Apr 4, 2013
  1. @yanick

    don't load commands unless they are used

    yanick authored
    this should make things much more zippy if we have
    more than a handful of commands.
This page is out of date. Refresh to see the latest.
Showing with 8 additions and 6 deletions.
  1. +8 −6 lib/MooX/Cmd.pm
View
14 lib/MooX/Cmd.pm
@@ -5,6 +5,7 @@ use strict;
use warnings;
use Carp;
use Module::Pluggable::Object;
+use Module::Runtime qw/ use_module /;
use Regexp::Common;
use Data::Record;
use Package::Stash;
@@ -34,13 +35,12 @@ sub import {
# i have no clue why 'only' and 'except' seems to not fulfill what i need or are bugged in M::P - Getty
my @cmd_plugins = grep {
- croak "you need an '".$execute_method_name."' function in ".$_ unless $_->can($execute_method_name);
my $class = $_;
- $class =~ s/${base}:://g;
- $class =~ /:/ ? 0 : 1;
+ $class =~ s/${base}:://;
+ $class !~ /:/;
} Module::Pluggable::Object->new(
search_path => $base,
- require => 1,
+ require => 0,
)->plugins;
my $stash = Package::Stash->new($caller);
@@ -71,8 +71,10 @@ sub import {
my $cmd;
while (my $arg = shift @args) {
- if (defined $cmds{$arg}) {
- $cmd = $cmds{$arg};
+ if ( $cmd = $cmds{$arg}) {
+ use_module( $cmd );
+ croak "you need an '".$execute_method_name."' function in ".$cmd
+ unless $cmd->can($execute_method_name);
last;
} else {
push @used_args, $arg;
Something went wrong with that request. Please try again.