File Coverage

blib/lib/Shell/Amazon/S3/CommandDispatcher.pm
Criterion Covered Total %
statement 12 18 66.6
branch 0 2 0.0
condition n/a
subroutine 4 5 80.0
pod 0 1 0.0
total 16 26 61.5


line stmt bran cond sub pod time code
1             package Shell::Amazon::S3::CommandDispatcher;
2 1     1   3 use Moose;
  1         2  
  1         5  
3 1     1   4421 use Module::Pluggable::Object;
  1         5143  
  1         30  
4 1     1   5 use Class::MOP;
  1         1  
  1         16  
5 1     1   334 use Shell::Amazon::S3::Utils;
  1         1  
  1         158  
6              
7             has 'dispatch_table' => (
8             is => 'ro',
9             isa => 'HashRef',
10             required => 1,
11             default => sub {
12             my $finder = Module::Pluggable::Object->new(
13             search_path => 'Shell::Amazon::S3::Command', );
14             my @commands = $finder->plugins;
15             Class::MOP::load_class($_) for @commands;
16             my %table
17             = map { Shell::Amazon::S3::Utils->classsuffix($_) => $_->new }
18             @commands;
19             \%table;
20             }
21             );
22              
23             sub dispatch {
24 0     0 0   my ( $self, $command, $args ) = @_;
25 0           my $result;
26 0 0         if ( exists $self->dispatch_table->{$command} ) {
27 0           $result = $self->dispatch_table->{$command}->do_execute($args);
28             }
29             else {
30 0           $result = 'Unknown command:' . $command;
31             }
32 0           $result;
33             }
34              
35             __PACKAGE__->meta->make_immutable;
36              
37             1;