diff --git a/cpanm b/cpanm index 7fc69ee2a..77751d950 100755 --- a/cpanm +++ b/cpanm @@ -42,6 +42,7 @@ sub new { perl => $^X, argv => undef, hooks => {}, + plugins => [], @_, }, $class; } @@ -61,6 +62,7 @@ sub parse_options { 'V|version' => sub { $self->{action} = 'version' }, 'perl' => \$self->{perl}, 'recent' => sub { $self->{action} = 'show_recent' }, + 'list-plugins' => sub { $self->{action} = 'list_plugins' }, 'installdeps' => \$self->{installdeps}, 'interactive' => \$self->{interactive}, 'i|install' => sub { $self->{cmd} = 'install' }, @@ -201,13 +203,19 @@ sub load_plugin { $self->chat("Loading plugin $file\n"); + my $plugin = { name => $name, file => $file }; + my @attr = qw( name description author version api_version synopsis ); + my $dsl = join "\n", map "sub $_ { \$plugin->{$_} = shift }", @attr; + (my $package = $file) =~ s/[^a-zA-Z0-9_]/_/g; my $code = do { open my $io, "<$file"; local $/; <$io> }; eval "package App::cpanplus::plugin::$package;\n". - "use strict;\n" . + "use strict;\n$dsl\n" . "sub hook { \$self->hook('$name', \@_) };\n$code"; $self->diag("! Loading plugin $file faield: $@") if $@; + + push @{$self->{plugins}}, $plugin; } sub hook { @@ -376,6 +384,16 @@ sub show_recent { return 1; } +sub list_plugins { + my $self = shift; + + for my $plugin (@{$self->{plugins}}) { + print "$plugin->{name} - $plugin->{description}\n"; + } + + return 1; +} + sub self_upgrade { my $self = shift; $self->{argv} = [ 'App::cpanminus' ]; diff --git a/plugins/bundle b/plugins/bundle index 776d9ddfe..b2c5070c7 100644 --- a/plugins/bundle +++ b/plugins/bundle @@ -1,5 +1,8 @@ -# NAME: bundle - grab dependencies from Bundle:: -# AUTHOR: Tatsuhiko Miyagawa +name 'bundle'; +description 'dependencies from Bundle::'; +author 'Tatsuhiko Miyagawa'; + +api_version 0.1; hook find_deps => sub { my $args = shift; diff --git a/plugins/cp562an b/plugins/cp562an index bca9371e5..c7f0ba901 100644 --- a/plugins/cp562an +++ b/plugins/cp562an @@ -1,6 +1,8 @@ -# XXX This does not work -# NAME: cp562an - Use CP5.6.2AN (or other similar) mirrors -# AUTHOR: Tatsuhiko Miyagawa +name 'cp562an'; +description 'Use CP5.6.2AN (or other similar) mirrors'; +author 'Tatsuhiko Miyagawa'; + +api_version 0.1; my $mirror_base = 'http://cp__WHAT__an.barnyard.co.uk/'; diff --git a/plugins/cpandb b/plugins/cpandb index 83620699a..3217e3b5c 100644 --- a/plugins/cpandb +++ b/plugins/cpandb @@ -1,5 +1,8 @@ -# NAME: cpandb - query CPAN DB rather than scraping search.cpan.org -# AUTHOR: Tatsuhiko Miyagawa +name 'cpandb'; +description 'query CPAN DB rather than scraping search.cpan.org'; +author 'Tatsuhiko Miyagawa'; + +api_version 0.1; # This is a proof-of-concept plugin: # DO NOT USE THIS PLUGIN - the server hardcoded here is not frequently updated diff --git a/plugins/cpanfresh b/plugins/cpanfresh index 9bdfa6375..19ef853e6 100644 --- a/plugins/cpanfresh +++ b/plugins/cpanfresh @@ -1,5 +1,8 @@ -# NAME: cpanfresh - Fetch the latest release from http://friendfeed.com/cpan -# AUTHOR: Tatsuhiko Miyagawa +name 'cpanfresh'; +description 'Fetch the latest release from http://friendfeed.com/cpan'; +author 'Tatsuhiko Miyagawa'; + +api_version 0.1; my $entries; diff --git a/plugins/dist_ini b/plugins/dist_ini index 8af0b441b..0a42c3987 100644 --- a/plugins/dist_ini +++ b/plugins/dist_ini @@ -1,5 +1,8 @@ -# NAME: dist_ini - Find depdencies and extract META info from dist.ini -# AUTHOR: Tatsuhiko Miyagawa +name 'dist_ini'; +description 'Find depdencies and extract META info from dist.ini'; +author 'Tatsuhiko Miyagawa'; + +api_version 0.1; # This is a proof of concept and not really useful since most # distributions heavily use Dist::Zilla's feature to mangle docs, diff --git a/plugins/fast_syncing_mirrors b/plugins/fast_syncing_mirrors index d25fbeea1..914ff5bf3 100644 --- a/plugins/fast_syncing_mirrors +++ b/plugins/fast_syncing_mirrors @@ -1,5 +1,8 @@ -# NAME: fast_syncing_mirrors - Use fast-syncing PAUSE mirrors -# AUTHOR: Tatsuhiko Miyagawa +name 'fast_syncing_mirrors'; +description 'Use fast-syncing PAUSE mirrors'; +author 'Tatsuhiko Miyagawa'; + +api_version 0.1; hook configure_mirrors => sub { my $args = shift; diff --git a/plugins/git_site_perl b/plugins/git_site_perl index 865605156..9aea9d412 100644 --- a/plugins/git_site_perl +++ b/plugins/git_site_perl @@ -1,5 +1,6 @@ -# NAME: git_site_perl - Hooks to keep site_perl in git -# AUTHOR: Tatsuhiko Miyagawa +name 'git_site_perl'; +description 'Hooks to keep site_perl in git'; +author 'Tatsuhiko Miyagawa'; use Config; use Cwd; diff --git a/plugins/github b/plugins/github index 5449c8394..b41877bb9 100644 --- a/plugins/github +++ b/plugins/github @@ -1,6 +1,9 @@ -# NAME: github - Install distributions from github -# AUTHOR: Tatsuhiko Miyagawa -# SYNOPSIS: cpanm github:miyagawa/Plack +name 'github'; +description 'Install distributions from github'; +synopsis 'cpanm github:miyagawa/Plack'; +author 'Tatsuhiko Miyagawa'; + +api_version 0.1; hook locate_dist => sub { my $args = shift; diff --git a/plugins/gitpan b/plugins/gitpan index 080d754d7..46b653ea7 100644 --- a/plugins/gitpan +++ b/plugins/gitpan @@ -1,6 +1,9 @@ -# NAME: gitpan - Install modules from gitpan -# AUTHOR: Tatsuhiko Miyagawa -# SYNOPSIS: cpanm gitpan:CGI-1.22 +name 'gitpan'; +description 'Install modules from gitpan'; +synopsis 'cpanm gitpan:CGI-1.22'; +author 'Tatsuhiko Miyagawa'; + +api_version 0.1; hook locate_dist => sub { my $args = shift; diff --git a/plugins/growl b/plugins/growl index 874371a07..3b155b126 100644 --- a/plugins/growl +++ b/plugins/growl @@ -1,5 +1,8 @@ -# NAME: growl - Growl notifications -# AUTHOR: Tatsuhiko Miyagawa +name 'growl'; +description 'Growl notifications'; +author 'Tatsuhiko Miyagawa'; + +api_version 0.1; my $growlnotify; diff --git a/plugins/minicpan b/plugins/minicpan index 6b5991475..b239513ec 100644 --- a/plugins/minicpan +++ b/plugins/minicpan @@ -1,5 +1,8 @@ -# NAME: minicpan - fallback to local minicpan when a dist is not found -# AUTHOR: Tatsuhiko Miyagawa +name 'minicpan'; +description 'fallback to local minicpan when a dist is not found'; +author 'Tatsuhiko Miyagawa'; + +api_version 0.1; my $minicpan_rc = File::Spec->catfile($ENV{HOME}, ".minicpanrc"); my $minicpan_home = find_home($minicpan_rc) || File::Spec->catfile($ENV{HOME}, "minicpan"); diff --git a/plugins/p5i b/plugins/p5i index 54179f304..9e9588df4 100644 --- a/plugins/p5i +++ b/plugins/p5i @@ -1,5 +1,8 @@ -# NAME: p5i - Support .p5i file -# AUTHOR: Tatsuhiko Miyagawa +name 'p5i'; +description 'Support .p5i file'; +author 'Tatsuhiko Miyagawa'; + +api_version 0.1; hook locate_dist => sub { my $args = shift; diff --git a/plugins/query_mirror b/plugins/query_mirror index 9780e8e82..cface731d 100644 --- a/plugins/query_mirror +++ b/plugins/query_mirror @@ -1,5 +1,8 @@ -# NAME: query_mirror - mst's hack to get redirects by module name on CPAN mirrors -# AUTHOR: Tatsuhiko Miyagawa +name 'query_mirror'; +description "mst's hack to get redirects by module name on CPAN mirrors" +author 'Tatsuhiko Miyagawa'; + +api_version 0.1; my $mirror = "http://cpan.shadowcatprojects.net"; diff --git a/plugins/verify_signature b/plugins/verify_signature index 48d02311e..0bd4cc06d 100644 --- a/plugins/verify_signature +++ b/plugins/verify_signature @@ -1,5 +1,8 @@ -# NAME: verify_signature - Verify SIGNATURE before installing -# AUTHOR: Tatsuhiko Miyagawa +name 'verify_signature'; +description 'Verify SIGNATURE before installing'; +author 'Tatsuhiko Miyagawa'; + +api_version 0.1; my $cpansign;