lib/Shell/Amazon/S3.pm

filter: Statementstmt 35.4% 28 / 79 Branchbran 0.0% 0 / 18 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 31.8% 7 / 22 Podpod 0.0% 0 / 11 totaltotal 26.9% 35 / 130 SCAR 38.3
CC
10
Cov
29%
run_once
12.0
eval
12.0
__ANON__
6.0
CRAP 46.0
« lib/Shell/Amazon/S3/Command/setacl.pm ↑ Summary lib/Shell/Amazon/S3/Plugin/ReadLineHistory.pm »
1 package Shell::Amazon::S3;
2 1 ▶use Term::ReadLine;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use namespace::clean -except => ['meta'];
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use Shell::Amazon::S3::CommandDispatcher;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use Shell::Amazon::S3::ConfigLoader;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use Perl6::Say;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 1 our $VERSION = '0.04_02';
10  
11 1 with 'MooseX::Object::Pluggable';
12  
13 has 'term' => (
14 is => 'rw',
15 required => 1,
16 0 ▶ default => sub { Term::ReadLine->new('Amazon S3 shell') }
Subroutine __ANON__: not called CC=1 SCAR=6.9
17 1 );
18  
19 has 'prompt' => (
20 is => 'rw',
21 required => 1,
22 0 ▶ default => sub {'psh3ll> '}
Subroutine __ANON__: not called CC=1 SCAR=6.9
23 1 );
24  
25 has 'out_fh' => (
26 is => 'rw',
27 required => 1,
28 lazy => 1,
29 0 ▶ default => sub { shift->term->OUT || \*STDOUT; }
Subroutine __ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
(shift())->term->OUT or \*STDOUT 0 0 0
30 1 );
31  
32 has 'dispatcher' => (
33 is => 'rw',
34 required => 1,
35 0 ▶ default => sub { Shell::Amazon::S3::CommandDispatcher->new }
Subroutine __ANON__: not called CC=1 SCAR=6.9
36 1 );
37  
38 sub run {
39 0 ▶ my ($self) = @_;
Subroutine run: not called CC=2 SCAR=17.9
Pod undocumented
40 0 $self->show_banner;
41 0 $self->setup;
42 0 ▶ while ( $self->run_once ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->run_once) 0 0 0
43  
44 # keep looping
45 }
46 }
47  
48 sub setup {
49 0 ▶ my ($self) = @_;
Subroutine setup: not called CC=1 SCAR=6.9
Pod undocumented
50 0 $self->setup_config;
51 }
52  
53 sub setup_config {
54 0 ▶ my ($self) = @_;
Subroutine setup_config: not called CC=1 SCAR=6.9
Pod undocumented
55 0 my $config_loader = Shell::Amazon::S3::ConfigLoader->new;
56 0 $config_loader->load;
57 }
58  
59 sub run_once {
60 0 ▶ my ($self) = @_;
Subroutine run_once: not called CC=3 SCAR=24.8
Pod undocumented
61 0 my $line = $self->read;
62 0 ▶ return unless defined($line); # undefined value == EOF
Branch: 1 branch
BranchTrueFalseTotal
unless defined $line 0 0 0
63 0 my $result = $self->eval($line);
64 0 eval { $self->print($result); };
65 0 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
66 0 my $error = $@;
67 0 eval { $self->print("Error printing! - $error\n"); };
68 }
69 0 return 1;
70 }
71  
72 sub read {
73 0 ▶ my ($self) = @_;
Subroutine read: not called CC=1 SCAR=6.9
Pod undocumented
74 0 return $self->term->readline( $self->prompt );
75 }
76  
77 sub eval {
78 0 ▶ my ( $self, $line ) = @_;
Subroutine eval: not called CC=3 SCAR=24.8
Pod undocumented
79 0 my ( $command, $args ) = $self->parse_input($line);
80 0 ▶ return unless defined($command);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $command 0 0 0
81 0 my $result = $self->execute( $command, $args );
82 0 ▶ exit if $result eq 'EXIT';
Branch: 1 branch
BranchTrueFalseTotal
if $result eq "EXIT" 0 0 0
83 0 return $result;
84 }
85  
86 sub parse_input {
87 0 ▶ my ( $self, $line ) = @_;
Subroutine parse_input: not called CC=2 SCAR=17.9
Pod undocumented
88 0 my @tokens = split( /\s/, $line );
89 0 ▶ return unless @tokens >= 1;
Branch: 1 branch
BranchTrueFalseTotal
unless @tokens >= 1 0 0 0
90 0 my $command = shift @tokens;
91 0 return ( $command, \@tokens );
92 }
93  
94 sub execute {
95 0 ▶ my ( $self, $command, $args ) = @_;
Subroutine execute: not called CC=2 SCAR=17.9
Pod undocumented
96 0 my $result = eval { $self->dispatcher->dispatch( $command, $args ); };
97 0 ▶ return $self->error_return( "Runtime error", $@ ) if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 0 0
98 0 return $result;
99 }
100  
101 sub error_return {
102 0 ▶ my ( $self, $type, $error ) = @_;
Subroutine error_return: not called CC=1 SCAR=6.9
Pod undocumented
103 0 return "${type}: ${error}";
104 }
105  
106 sub print {
107 0 ▶ my ( $self, $result ) = @_;
Subroutine print: not called CC=2 SCAR=11.6
Pod undocumented
108 0 my $fh = $self->out_fh;
109 1 ▶ no warnings 'uninitialized';
Subroutine BEGIN: called CC=1 SCAR=0.0
110 0 print $fh "$result";
111 0 ▶ print $fh "\n" if $self->term->ReadLine =~ /Gnu/;
Branch: 1 branch
BranchTrueFalseTotal
if $self->term->ReadLine =~ /Gnu/ 0 0 0
112 }
113  
114 sub show_banner {
115 0 ▶ say "Welcome to pSh3ll (Amazon S3 command shell for Perl) (c) 2008 Takatoshi Kitano.";
Subroutine show_banner: not called CC=1 SCAR=6.9
Pod undocumented
116 0 say "Type 'help' for command list.";
117 0 say ;
118 }
119  
120 1 1;
121  
122 __END__
123  
124 =head1 NAME
125  
126 Shell::Amazon::S3 - Shell for Amazon S3
127  
128 =head1 SYNOPSIS
129  
130 use Shell::Amazon::S3;
131  
132 my $shell = Shell::Amazon::S3->new;
133 $shell->load_plugins($_) for qw(ReadLineHistory Completion);
134 $shell->run;
135  
136 Alternatively, use the 'psh3ll.pl' script installed with the distribution
137  
138 system$ psh3ll.pl
139  
140 =head1 DESCRIPTION
141  
142 Shell::Amazon::S3 is Shell for Amazon S3
143  
144 =head1 AUTHOR
145  
146 Takatoshi KitanoE<lt>kitano.t@gmail.comE<gt>
147  
148 =head1 SEE ALSO
149  
150 =head1 LICENSE
151  
152 This library is free software; you can redistribute it and/or modify
153 it under the same terms as Perl itself.
154  
155 =cut
« lib/Shell/Amazon/S3/Command/setacl.pm ↑ Summary lib/Shell/Amazon/S3/Plugin/ReadLineHistory.pm »