File Coverage

lib/Module/AnyEvent/Helper/PPI/Transform/Net/Amazon/S3/Client/Bucket.pm
Criterion Covered Total %
statement 12 36 33.3
branch 0 12 0.0
condition 0 21 0.0
subroutine 4 11 36.3
pod 1 1 100.0
total 17 81 20.9


line stmt bran cond sub pod time code
1             package Module::AnyEvent::Helper::PPI::Transform::Net::Amazon::S3::Client::Bucket;
2              
3             # ABSTRACT: Additional transformer for Module::AnyEvent::Helper
4             our $VERSION = 'v0.03.0.60'; # VERSION
5              
6 1     1   761 use strict;
  1         3  
  1         31  
7 1     1   6 use warnings;
  1         2  
  1         25  
8              
9 1     1   6 use parent qw(Module::AnyEvent::Helper::PPI::Transform::Net::Amazon::S3);
  1         2  
  1         6  
10              
11 1     1   1137 use Module::AnyEvent::Helper::PPI::Transform qw(is_function_declaration copy_children emit_cv replace_as_async);
  1         15100  
  1         783  
12              
13             my $list_def = PPI::Document->new(\'sub list { return shift->list_async(@_); }');
14             my $return_undef = PPI::Document->new(\'if($end) { $___cv___->send; return $___cv___; }');
15             my $var_def = PPI::Document->new(\'my $marker = $conf->{marker};my $max_keys = $conf->{max_keys} || 1000;');
16             my $req_def_ = <<'EOF';
17             my $http_request = AnyEvent::Net::Amazon::S3::Request::ListBucket->new(
18             s3 => $self->client->s3,
19             bucket => $self->name,
20             marker => $marker,
21             prefix => $prefix,
22             max_keys => $max_keys,
23             )->http_request;
24             EOF
25             my $req_def = PPI::Document->new(do { chop($req_def_); \$req_def_ });
26              
27             sub document
28             {
29 0     0 1   my ($self, $doc) = @_;
30 0           $self->SUPER::document($doc);
31              
32             # Find target
33             my $list_decl = $doc->find_first(sub {
34 0 0 0 0     $_[1]->isa('PPI::Token::Word') && is_function_declaration($_[1]) && $_[1]->content eq 'list';
35 0           });
36             my $sub_block = $list_decl->snext_sibling->find_first(sub {
37 0 0   0     $_[1]->isa('PPI::Token::Word') && $_[1]->content eq 'sub';
38 0           })->snext_sibling;
39              
40             # sub block transformation
41             my $target = $sub_block->find_first(sub {
42 0 0   0     $_[1]->isa('PPI::Token::Word') && $_[1]->content eq '_send_request_xpc';
43 0           });
44 0           replace_as_async($target, '_send_request_xpc_async', 0);
45 0           emit_cv($sub_block);
46 0           $list_decl->set_content('list_async');
47             my $target2 = $sub_block->find_first(sub {
48 0 0   0     $_[1]->isa('PPI::Token::Symbol') && $_[1]->content eq '$end';
49 0           });
50 0           copy_children(undef, $target2->statement->snext_sibling, $return_undef);
51 0           $target2->statement->delete;
52              
53             # Additional options
54             my $var = $doc->find_first(sub {
55 0 0 0 0     $_[1]->isa('PPI::Statement::Variable') &&
      0        
      0        
56             $_[1]->schild(0)->isa('PPI::Token::Word') && $_[1]->schild(0)->content eq 'my' &&
57             $_[1]->schild(1)->isa('PPI::Token::Symbol') && $_[1]->schild(1)->content eq '$marker';
58 0           });
59 0           copy_children(undef, $var->snext_sibling, $var_def);
60 0           $var->delete;
61             my $req = $sub_block->find_first(sub {
62 0 0 0 0     $_[1]->isa('PPI::Statement::Variable') &&
      0        
      0        
63             $_[1]->schild(0)->isa('PPI::Token::Word') && $_[1]->schild(0)->content eq 'my' &&
64             $_[1]->schild(1)->isa('PPI::Token::Symbol') && $_[1]->schild(1)->content eq '$http_request';
65 0           });
66 0           copy_children(undef, $req->snext_sibling, $req_def);
67 0           $req->delete;
68              
69              
70             # Add list() definition
71 0           copy_children($list_decl->statement, undef, $list_def);
72             }
73              
74             1;
75              
76             __END__
77              
78             =pod
79              
80             =encoding UTF-8
81              
82             =head1 NAME
83              
84             Module::AnyEvent::Helper::PPI::Transform::Net::Amazon::S3::Client::Bucket - Additional transformer for Module::AnyEvent::Helper
85              
86             =head1 VERSION
87              
88             version v0.03.0.60
89              
90             =head1 SYNOPSIS
91              
92             use Module::AnyEvent::Helper::Filter -transformer => 'Net::Amazon::S3::Client::Bucket', -target => 'Net::Amazon::S3::Client::Bucket';
93              
94             =head1 DESCRIPTION
95              
96             This class is not intended to use directly.
97              
98             =head1 AUTHOR
99              
100             Yasutaka ATARASHI <yakex@cpan.org>
101              
102             =head1 COPYRIGHT AND LICENSE
103              
104             This software is copyright (c) 2012 by Yasutaka ATARASHI.
105              
106             This is free software; you can redistribute it and/or modify it under
107             the same terms as the Perl 5 programming language system itself.
108              
109             =cut