Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

only load commands if used #2

Merged
merged 1 commit into from 6 months ago

2 participants

Yanick Champoux Torsten Raudssus
Yanick Champoux

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

Yanick Champoux 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
Torsten Raudssus Getty merged commit 03139b6 into from October 29, 2013
Torsten Raudssus Getty closed this October 29, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 1 unique commit by 1 author.

Apr 03, 2013
Yanick Champoux 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
This page is out of date. Refresh to see the latest.

Showing 1 changed file with 8 additions and 6 deletions. Show diff stats Hide diff stats

  1. 14  lib/MooX/Cmd.pm
14  lib/MooX/Cmd.pm
@@ -5,6 +5,7 @@ use strict;
5 5
 use warnings;
6 6
 use Carp;
7 7
 use Module::Pluggable::Object;
  8
+use Module::Runtime qw/ use_module /;
8 9
 use Regexp::Common;
9 10
 use Data::Record;
10 11
 use Package::Stash;
@@ -34,13 +35,12 @@ sub import {
34 35
 
35 36
 	# i have no clue why 'only' and 'except' seems to not fulfill what i need or are bugged in M::P - Getty
36 37
 	my @cmd_plugins = grep {
37  
-		croak "you need an '".$execute_method_name."' function in ".$_ unless $_->can($execute_method_name);
38 38
 		my $class = $_;
39  
-		$class =~ s/${base}:://g;
40  
-		$class =~ /:/ ? 0 : 1;
  39
+		$class =~ s/${base}:://;
  40
+		$class !~ /:/;
41 41
 	} Module::Pluggable::Object->new(
42 42
 		search_path => $base,
43  
-		require => 1,
  43
+		require => 0,
44 44
 	)->plugins;
45 45
 	
46 46
 	my $stash = Package::Stash->new($caller);
@@ -71,8 +71,10 @@ sub import {
71 71
 		my $cmd;
72 72
 	
73 73
 		while (my $arg = shift @args) {
74  
-			if (defined $cmds{$arg}) {
75  
-				$cmd = $cmds{$arg};
  74
+			if ( $cmd = $cmds{$arg}) {
  75
+                use_module( $cmd );
  76
+                croak "you need an '".$execute_method_name."' function in ".$cmd 
  77
+                    unless $cmd->can($execute_method_name);
76 78
 				last;
77 79
 			} else {
78 80
 				push @used_args, $arg;
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.