#!/usr/bin/perl

=head1 NAME

cpan-patches - work with CPAN patch sets

=head1 SYNOPSIS

	cpan-patches [--patch-set FOLDER] CMD
	
		patch  - will apply all patches
		list   - list all patches
		?      - check out CPAN::Patches::Plugin::* for additional commands
		
		--patch-set FOLDER
			is the FOLDER where the patch-sets are stored

=head1 DESCRIPTION

=cut


use strict;
use warnings;

use Getopt::Long;
use Pod::Usage;
use CPAN::Patches 0.02;

use 5.010;

exit main();

sub main {
	my $help;
	my $set_folder;
	GetOptions(
		'help|h' => \$help,
		'patch-set|s=s' => \$set_folder,
	) or pod2usage;
	pod2usage if $help;
	
	my $cmd = shift @ARGV;
	pod2usage if not $cmd;
	$cmd =~ s/-/_/;
	$cmd = 'cmd_'.$cmd;
	
	my $cpan_ps  = CPAN::Patches->new(
		$set_folder
		? ('patch_set_location' => $set_folder)
		: ()
	);
	pod2usage if not $cpan_ps->can($cmd);
	
	$cpan_ps->$cmd();
	
	return 0;
}
