| 1 | package WebService::Amazon::DynamoDB::Server; | ||||||||||||||||||||||||||||||||
| 2 | # ABSTRACT: Perl implementation of the DynamoDB server API, for testing | ||||||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||||||
| 4 | 9 | ▶ | use strict; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 5 | 9 | ▶ | use warnings; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||
| 7 | 9 | our $VERSION = '0.001'; | |||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||
| 9 | =head1 NAME | ||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||
| 11 | WebService::Amazon::DynamoDB - perl server implementation for the AWS DynamoDB API | ||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||
| 13 | =head1 VERSION | ||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||
| 15 | version 0.001 | ||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||
| 17 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||
| 19 | =cut | ||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||
| 21 | 9 | ▶ | use Mixin::Event::Dispatch::Bus; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||
| 23 | 9 | ▶ | use Encode; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 24 | 9 | ▶ | use Future; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 25 | 9 | ▶ | use Future::Utils qw(call); | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 26 | 9 | ▶ | use List::Util qw(min); | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 27 | 9 | ▶ | use List::UtilsBy qw(extract_by sort_by); | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 28 | 9 | ▶ | use Time::Moment; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||
| 30 | 9 | ▶ | use WebService::Amazon::DynamoDB::Server::Table; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 31 | 9 | ▶ | use WebService::Amazon::DynamoDB::Server::Item; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||
| 33 | 9 | ▶ | use constant LIST_TABLES_MAX => 100; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||
| 35 | 9 | our %API_METHODS = map {; $_ => 1 } qw( | |||||||||||||||||||||||||||||||
| 36 | list_tables | ||||||||||||||||||||||||||||||||
| 37 | create_table | ||||||||||||||||||||||||||||||||
| 38 | delete_table | ||||||||||||||||||||||||||||||||
| 39 | update_table | ||||||||||||||||||||||||||||||||
| 40 | describe_table | ||||||||||||||||||||||||||||||||
| 41 | get_item | ||||||||||||||||||||||||||||||||
| 42 | put_item | ||||||||||||||||||||||||||||||||
| 43 | ); | ||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||
| 45 | =head1 METHODS | ||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||
| 47 | =cut | ||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||
| 49 | =head2 new | ||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||
| 51 | =cut | ||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||
| 53 | 7 | ▶ | sub new { my $class = shift; bless {@_}, $class } | ||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||
| 55 | =head2 list_tables | ||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||
| 57 | Takes the following named parameters: | ||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||
| 59 | =over 4 | ||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||
| 61 | =item * ExclusiveStartTableName | ||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||
| 63 | =item * Limit | ||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||
| 65 | =back | ||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||
| 67 | Resolves to a hashref containing the following data: | ||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||
| 69 | =over 4 | ||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||
| 71 | =item * LastEvaluatedTableName | ||||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||
| 73 | =item * TableNames | ||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||
| 75 | =back | ||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||
| 77 | ListTables (p. 58) | ||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||
| 79 | =cut | ||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||
| 81 | 5 | ▶ | sub list_tables { | ||||||||||||||||||||||||||||||
|
Subroutine
list_tables: called CC=7 SCAR=19.5
Pod
documented
| |||||||||||||||||||||||||||||||||
| 82 | 5 | my ($self, %args) = @_; | |||||||||||||||||||||||||||||||
| 83 | 5 | my $req = { %args }; | |||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||
| 85 | 5 | ▶ | my @tables = sort_by { $_->name } @{$self->{tables}}; | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 86 | 5 | ▶ | if(exists $args{ExclusiveStartTableName}) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 87 | return $self->fail( | ||||||||||||||||||||||||||||||||
| 88 | list_tables => $req, | ||||||||||||||||||||||||||||||||
| 89 | 'ValidationException: table ' . $args{ExclusiveStartTableName} . ' not found', | ||||||||||||||||||||||||||||||||
| 90 | 3 | ▶ | ) unless $self->have_table($args{ExclusiveStartTableName}); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||
| 92 | 2 | ▶ | shift @tables while @tables && $tables[0]->name ne $args{ExclusiveStartTableName}; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
@tables and $tables[0]->name ne $args{"ExclusiveStartTableName"}
MC/DC50%1/2
@tables and $tables[0]->name ne $args{"ExclusiveStartTableName"}
@tables
$tables[0]->name ne $args{"ExclusiveStartTableName"}
Truth table66%2/3
A and B
A= @tablesB= $tables[0]->name ne $args{"ExclusiveStartTableName"}
| |||||||||||||||||||||||||||||||||
| 93 | } | ||||||||||||||||||||||||||||||||
| 94 | 4 | ▶ | my $limit = min(LIST_TABLES_MAX, $args{Limit} // ()); | ||||||||||||||||||||||||||||||
|
Condition66%2/3
$args{"Limit"} // ()
MC/DC0%0/2
$args{"Limit"} // ()
$args{"Limit"}
()
Truth table66%2/3
A // B
A= $args{"Limit"}B= ()
| |||||||||||||||||||||||||||||||||
| 95 | 4 | my %result; | |||||||||||||||||||||||||||||||
| 96 | 4 | ▶ | if(@tables > $limit) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 97 | 2 | my ($last) = splice @tables, $limit; | |||||||||||||||||||||||||||||||
| 98 | 2 | $result{LastEvaluatedTableName} = $last->name; | |||||||||||||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||||||||||||
| 100 | 4 | $result{TableNames} = [ map $_->name, @tables ]; | |||||||||||||||||||||||||||||||
| 101 | 4 | $self->done(list_tables => \%result, $req, \@tables) | |||||||||||||||||||||||||||||||
| 102 | } | ||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||
| 104 | =head2 create_table | ||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||
| 106 | CreateTable (p. 22) | ||||||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||||||
| 108 | =cut | ||||||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||||||
| 110 | 14 | ▶ | sub create_table { | ||||||||||||||||||||||||||||||
|
Subroutine
create_table: called CC=14 SCAR=26.8
Pod
documented
| |||||||||||||||||||||||||||||||||
| 111 | 14 | my ($self, %args) = @_; | |||||||||||||||||||||||||||||||
| 112 | 14 | my $req = { %args }; | |||||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||||||
| 114 | return $self->fail( | ||||||||||||||||||||||||||||||||
| 115 | create_table => $req, | ||||||||||||||||||||||||||||||||
| 116 | 'ValidationException - no AttributeDefinitions found' | ||||||||||||||||||||||||||||||||
| 117 | 14 | ▶ | ) unless exists $args{AttributeDefinitions}; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||||||
| 119 | return $self->fail( | ||||||||||||||||||||||||||||||||
| 120 | create_table => $req, | ||||||||||||||||||||||||||||||||
| 121 | 'ValidationException - no KeySchema found' | ||||||||||||||||||||||||||||||||
| 122 | 13 | ▶ | ) unless exists $args{KeySchema}; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||||||
| 124 | return $self->fail( | ||||||||||||||||||||||||||||||||
| 125 | create_table => $req, | ||||||||||||||||||||||||||||||||
| 126 | 'ValidationException - empty KeySchema found' | ||||||||||||||||||||||||||||||||
| 127 | 12 | ▶ | ) unless @{$args{KeySchema}}; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||||||
| 129 | return $self->fail( | ||||||||||||||||||||||||||||||||
| 130 | create_table => $req, | ||||||||||||||||||||||||||||||||
| 131 | 'ValidationException - too many items found in KeySchema' | ||||||||||||||||||||||||||||||||
| 132 | 11 | ▶ | ) if @{$args{KeySchema}} > 2; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||||||
| 134 | return $self->fail( | ||||||||||||||||||||||||||||||||
| 135 | create_table => $req, | ||||||||||||||||||||||||||||||||
| 136 | 'ValidationException - invalid KeyType, expected HASH' | ||||||||||||||||||||||||||||||||
| 137 | 11 | ▶ | ) unless ($args{KeySchema}[0]{KeyType} // '') eq 'HASH'; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
$args{"KeySchema"}[0]{"KeyType"} // ""
MC/DC0%0/1
$args{"KeySchema"}[0]{"KeyType"} // ""
$args{"KeySchema"}[0]{"KeyType"}
Truth table50%1/2
A
A= $args{"KeySchema"}[0]{"KeyType"}
| |||||||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||||||
| 139 | return $self->fail( | ||||||||||||||||||||||||||||||||
| 140 | create_table => $req, | ||||||||||||||||||||||||||||||||
| 141 | 'ValidationException - invalid KeyType, expected RANGE' | ||||||||||||||||||||||||||||||||
| 142 | 10 | ▶ | ) if @{$args{KeySchema}} > 1 && ($args{KeySchema}[1]{KeyType} // '') ne 'RANGE'; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition20%1/5
@{$args{"KeySchema"};} > 1 and ($args{"KeySchema"}[1]{"KeyType"} // "") ne "RANGE"
$args{"KeySchema"}[1]{"KeyType"} // ""
MC/DC0%0/2
@{$args{"KeySchema"};} > 1 and ($args{"KeySchema"}[1]{"KeyType"} // "") ne "RANGE"
@{$args{"KeySchema"};} > 1
$args{"KeySchema"}[1]{"KeyType"}
Truth table33%1/3
A and B
A= @{$args{"KeySchema"};} > 1B= $args{"KeySchema"}[1]{"KeyType"}
| |||||||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||||||
| 144 | 10 | my %attr = map {; $_->{AttributeName} => $_ } @{$args{AttributeDefinitions}}; | |||||||||||||||||||||||||||||||
| 145 | return $self->fail( | ||||||||||||||||||||||||||||||||
| 146 | create_table => $req, | ||||||||||||||||||||||||||||||||
| 147 | 'ValidationException - attribute ' . $_ . ' not found in AttributeDefinitions' | ||||||||||||||||||||||||||||||||
| 148 | 10 | ) for grep !exists $attr{$_}, map $_->{AttributeName}, @{$args{KeySchema}}; | |||||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||||||
| 150 | return $self->fail( | ||||||||||||||||||||||||||||||||
| 151 | create_table => $req, | ||||||||||||||||||||||||||||||||
| 152 | 'ValidationException - no ProvisionedThroughput found' | ||||||||||||||||||||||||||||||||
| 153 | 9 | ▶ | ) unless exists $args{ProvisionedThroughput}; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||||||
| 155 | return $self->fail( | ||||||||||||||||||||||||||||||||
| 156 | create_table => $req, | ||||||||||||||||||||||||||||||||
| 157 | 'ValidationException - no ProvisionedThroughput found' | ||||||||||||||||||||||||||||||||
| 158 | 8 | ▶ | ) unless exists $args{TableName}; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||||||
| 160 | return $self->fail( | ||||||||||||||||||||||||||||||||
| 161 | create_table => $req, | ||||||||||||||||||||||||||||||||
| 162 | 'ResourceInUseException - this table exists already' | ||||||||||||||||||||||||||||||||
| 163 | 7 | ▶ | ) if $self->have_table($args{TableName}); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||||||
| 165 | 6 | $args{TableStatus} = 'CREATING'; | |||||||||||||||||||||||||||||||
| 166 | 6 | $args{ItemCount} = 0; | |||||||||||||||||||||||||||||||
| 167 | 6 | $args{TableSizeBytes} = 0; | |||||||||||||||||||||||||||||||
| 168 | 6 | $args{CreationDateTime} = Time::Moment->now; | |||||||||||||||||||||||||||||||
| 169 | 6 | my $tbl = $self->add_table(%args); | |||||||||||||||||||||||||||||||
| 170 | $self->done(create_table => { | ||||||||||||||||||||||||||||||||
| 171 | TableDescription => { | ||||||||||||||||||||||||||||||||
| 172 | %args, | ||||||||||||||||||||||||||||||||
| 173 | CreationDateTime => $args{CreationDateTime}->to_string, | ||||||||||||||||||||||||||||||||
| 174 | } | ||||||||||||||||||||||||||||||||
| 175 | 6 | }, $req, $tbl); | |||||||||||||||||||||||||||||||
| 176 | } | ||||||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||||||
| 178 | =head2 describe_table | ||||||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||||||
| 180 | DescribeTable (p. 47) | ||||||||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||||||
| 182 | =cut | ||||||||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||||||
| 184 | 9 | ▶ | sub describe_table { | ||||||||||||||||||||||||||||||
|
Subroutine
describe_table: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 185 | 9 | my ($self, %args) = @_; | |||||||||||||||||||||||||||||||
| 186 | 9 | my $req = { %args }; | |||||||||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||||||||||
| 188 | 9 | my $name = delete $args{TableName}; | |||||||||||||||||||||||||||||||
| 189 | 5 | ▶ | $self->validate_table_state($name => 'ACTIVE')->then(sub { | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 190 | 5 | my $tbl = $self->{table_map}{$name}; | |||||||||||||||||||||||||||||||
| 191 | 5 | $self->done(describe_table => { | |||||||||||||||||||||||||||||||
| 192 | Table => $tbl | ||||||||||||||||||||||||||||||||
| 193 | }, $req, $tbl) | ||||||||||||||||||||||||||||||||
| 194 | 4 | ▶ | }, sub { | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 195 | 4 | $self->fail(describe_table => $req, @_) | |||||||||||||||||||||||||||||||
| 196 | }) | ||||||||||||||||||||||||||||||||
| 197 | 9 | } | |||||||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||||||
| 199 | =head2 update_table | ||||||||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||||||
| 201 | UpdateTable (p. 119) | ||||||||||||||||||||||||||||||||
| 202 | |||||||||||||||||||||||||||||||||
| 203 | =cut | ||||||||||||||||||||||||||||||||
| 204 | |||||||||||||||||||||||||||||||||
| 205 | 3 | ▶ | sub update_table { | ||||||||||||||||||||||||||||||
|
Subroutine
update_table: called CC=1 SCAR=0.1
Pod
documented
| |||||||||||||||||||||||||||||||||
| 206 | 3 | my ($self, %args) = @_; | |||||||||||||||||||||||||||||||
| 207 | 3 | my $req = { %args }; | |||||||||||||||||||||||||||||||
| 208 | |||||||||||||||||||||||||||||||||
| 209 | 3 | my $name = delete $args{TableName}; | |||||||||||||||||||||||||||||||
| 210 | 1 | ▶ | $self->validate_table_state($name => 'ACTIVE')->then(sub { | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=8 SCAR=21.6
| |||||||||||||||||||||||||||||||||
| 211 | 1 | my $tbl = $self->{table_map}{$name}; | |||||||||||||||||||||||||||||||
| 212 | 1 | my %update; | |||||||||||||||||||||||||||||||
| 213 | 1 | ▶ | if(my $throughput = delete $args{ProvisionedThroughput}) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 214 | 1 | $update{ProvisionedThroughput}{$_} = $throughput->{$_} for grep exists $throughput->{$_}, qw(ReadCapacityUnits WriteCapacityUnits); | |||||||||||||||||||||||||||||||
| 215 | } | ||||||||||||||||||||||||||||||||
| 216 | 1 | ▶ | if(my $index = delete $args{GlobalSecondaryIndexUpdates}) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 217 | 0 | $update{GlobalSecondaryIndexUpdates}{$_} = $index->{$_} for keys %$index; | |||||||||||||||||||||||||||||||
| 218 | } | ||||||||||||||||||||||||||||||||
| 219 | 1 | ▶ | return $self->fail( | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 220 | update_table => $req, | ||||||||||||||||||||||||||||||||
| 221 | 'ValidationException - invalid keys provided' | ||||||||||||||||||||||||||||||||
| 222 | ) if keys %args; | ||||||||||||||||||||||||||||||||
| 223 | 1 | for my $k (keys %update) { | |||||||||||||||||||||||||||||||
| 224 | 1 | $tbl->{$k}{$_} = $update{$k}{$_} for keys %{$update{$k}}; | |||||||||||||||||||||||||||||||
| 225 | } | ||||||||||||||||||||||||||||||||
| 226 | 1 | ▶ | $self->table_status($name => 'UPDATING')->then(sub { | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 227 | 1 | $self->done(update_table => { | |||||||||||||||||||||||||||||||
| 228 | TableDescription => $tbl | ||||||||||||||||||||||||||||||||
| 229 | }, $req, $tbl) | ||||||||||||||||||||||||||||||||
| 230 | }) | ||||||||||||||||||||||||||||||||
| 231 | 1 | ▶ | }, sub { | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 232 | 2 | $self->fail(update_table => $req, @_) | |||||||||||||||||||||||||||||||
| 233 | }) | ||||||||||||||||||||||||||||||||
| 234 | 3 | } | |||||||||||||||||||||||||||||||
| 235 | |||||||||||||||||||||||||||||||||
| 236 | =head2 delete_table | ||||||||||||||||||||||||||||||||
| 237 | |||||||||||||||||||||||||||||||||
| 238 | DeleteTable (p. 43) | ||||||||||||||||||||||||||||||||
| 239 | |||||||||||||||||||||||||||||||||
| 240 | =cut | ||||||||||||||||||||||||||||||||
| 241 | |||||||||||||||||||||||||||||||||
| 242 | 4 | ▶ | sub delete_table { | ||||||||||||||||||||||||||||||
|
Subroutine
delete_table: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 243 | 4 | my ($self, %args) = @_; | |||||||||||||||||||||||||||||||
| 244 | 4 | my $req = { %args }; | |||||||||||||||||||||||||||||||
| 245 | |||||||||||||||||||||||||||||||||
| 246 | 4 | my $name = delete $args{TableName}; | |||||||||||||||||||||||||||||||
| 247 | 2 | ▶ | $self->validate_table_state($name => qw(ACTIVE DELETING))->then(sub { | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.0
| |||||||||||||||||||||||||||||||||
| 248 | 2 | ▶ | return $self->fail( | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 249 | delete_table => $req, | ||||||||||||||||||||||||||||||||
| 250 | 'ValidationException - invalid keys provided' | ||||||||||||||||||||||||||||||||
| 251 | ) if keys %args; | ||||||||||||||||||||||||||||||||
| 252 | 2 | my $tbl = $self->{table_map}{$name}; | |||||||||||||||||||||||||||||||
| 253 | 2 | ▶ | $self->table_status($name => 'DELETING')->then(sub { | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 254 | 2 | $self->done(delete_table => { | |||||||||||||||||||||||||||||||
| 255 | TableDescription => $tbl | ||||||||||||||||||||||||||||||||
| 256 | }, $req, $tbl) | ||||||||||||||||||||||||||||||||
| 257 | }) | ||||||||||||||||||||||||||||||||
| 258 | 2 | ▶ | }, sub { | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 259 | 2 | $self->fail(delete_table => $req, @_) | |||||||||||||||||||||||||||||||
| 260 | }) | ||||||||||||||||||||||||||||||||
| 261 | 4 | } | |||||||||||||||||||||||||||||||
| 262 | |||||||||||||||||||||||||||||||||
| 263 | =head2 put_item | ||||||||||||||||||||||||||||||||
| 264 | |||||||||||||||||||||||||||||||||
| 265 | PutItem (p. 61) | ||||||||||||||||||||||||||||||||
| 266 | |||||||||||||||||||||||||||||||||
| 267 | =cut | ||||||||||||||||||||||||||||||||
| 268 | |||||||||||||||||||||||||||||||||
| 269 | 6 | ▶ | sub put_item { | ||||||||||||||||||||||||||||||
|
Subroutine
put_item: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 270 | 6 | my ($self, %args) = @_; | |||||||||||||||||||||||||||||||
| 271 | 6 | my $req = { %args }; | |||||||||||||||||||||||||||||||
| 272 | |||||||||||||||||||||||||||||||||
| 273 | 6 | my $name = delete $args{TableName}; | |||||||||||||||||||||||||||||||
| 274 | 3 | ▶ | $self->validate_table_state($name => 'ACTIVE')->then(sub { | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 275 | 3 | my $tbl = $self->{table_map}{$name}; | |||||||||||||||||||||||||||||||
| 276 | 2 | ▶ | $tbl->validate_id_for_item_data($args{Item})->then(sub { | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 277 | 2 | my $id = shift; | |||||||||||||||||||||||||||||||
| 278 | 2 | my $new = !exists $self->{data}{$name}{$id}; | |||||||||||||||||||||||||||||||
| 279 | 2 | my $item = $tbl->item_from_data(delete $args{Item}); | |||||||||||||||||||||||||||||||
| 280 | 2 | $self->{data}{$name}{$id} = $item; | |||||||||||||||||||||||||||||||
| 281 | |||||||||||||||||||||||||||||||||
| 282 | 2 | my %result; | |||||||||||||||||||||||||||||||
| 283 | Future->needs_all( | ||||||||||||||||||||||||||||||||
| 284 | $self->return_values(delete $args{ReturnValues}), | ||||||||||||||||||||||||||||||||
| 285 | $self->consumed_capacity(delete $args{ReturnConsumedCapacity}), | ||||||||||||||||||||||||||||||||
| 286 | $self->collection_metrics(delete $args{ReturnItemCollectionMetrics}), | ||||||||||||||||||||||||||||||||
| 287 | 2 | ▶ | )->then(sub { | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||
| 288 | # Only add the keys if they were requested | ||||||||||||||||||||||||||||||||
| 289 | 2 | for(qw(Attributes ConsumedCapacity ItemCollectionMetrics)) { | |||||||||||||||||||||||||||||||
| 290 | 6 | my $k = shift; | |||||||||||||||||||||||||||||||
| 291 | 6 | ▶ | $result{$_} = $k if defined $k | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 292 | } | ||||||||||||||||||||||||||||||||
| 293 | |||||||||||||||||||||||||||||||||
| 294 | # Commit the changes | ||||||||||||||||||||||||||||||||
| 295 | 2 | ▶ | ++$tbl->{ItemCount} if $new; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 296 | 2 | $tbl->{TableSizeBytes} += length Encode::decode('UTF-8', $id); | |||||||||||||||||||||||||||||||
| 297 | |||||||||||||||||||||||||||||||||
| 298 | 2 | $self->done(put_item => \%result, $req, $tbl, $item); | |||||||||||||||||||||||||||||||
| 299 | 0 | ▶ | }, sub { | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||
| 300 | 0 | $self->fail(put_item => $req, @_) | |||||||||||||||||||||||||||||||
| 301 | 2 | }); | |||||||||||||||||||||||||||||||
| 302 | 1 | ▶ | }, sub { | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 303 | 1 | $self->fail(put_item => $req, @_) | |||||||||||||||||||||||||||||||
| 304 | }) | ||||||||||||||||||||||||||||||||
| 305 | 3 | ▶ | }, sub { | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 306 | 3 | $self->fail(put_item => $req, @_) | |||||||||||||||||||||||||||||||
| 307 | }) | ||||||||||||||||||||||||||||||||
| 308 | 6 | } | |||||||||||||||||||||||||||||||
| 309 | |||||||||||||||||||||||||||||||||
| 310 | =head2 get_item | ||||||||||||||||||||||||||||||||
| 311 | |||||||||||||||||||||||||||||||||
| 312 | GetItem (p. 52) | ||||||||||||||||||||||||||||||||
| 313 | |||||||||||||||||||||||||||||||||
| 314 | =cut | ||||||||||||||||||||||||||||||||
| 315 | |||||||||||||||||||||||||||||||||
| 316 | 4 | ▶ | sub get_item { | ||||||||||||||||||||||||||||||
|
Subroutine
get_item: called CC=1 SCAR=2.3
Pod
documented
| |||||||||||||||||||||||||||||||||
| 317 | 4 | my ($self, %args) = @_; | |||||||||||||||||||||||||||||||
| 318 | 4 | my $req = { %args }; | |||||||||||||||||||||||||||||||
| 319 | |||||||||||||||||||||||||||||||||
| 320 | 4 | my $name = delete $args{TableName}; | |||||||||||||||||||||||||||||||
| 321 | 1 | ▶ | $self->validate_table_state($name => 'ACTIVE')->then(sub { | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=4.4
| |||||||||||||||||||||||||||||||||
| 322 | 1 | my $tbl = $self->{table_map}{$name}; | |||||||||||||||||||||||||||||||
| 323 | 0 | ▶ | $tbl->validate_id_for_item_data($args{Key})->then(sub { | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||
| 324 | 0 | my $id = shift; | |||||||||||||||||||||||||||||||
| 325 | 0 | my %result; | |||||||||||||||||||||||||||||||
| 326 | my $item; | ||||||||||||||||||||||||||||||||
| 327 | 0 | ▶ | if(exists $self->{data}{$name}{$id}) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 328 | 0 | $item = $result{Item} = $self->{data}{$name}{$id} | |||||||||||||||||||||||||||||||
| 329 | } | ||||||||||||||||||||||||||||||||
| 330 | 0 | ▶ | return $self->consumed_capacity(delete $args{ReturnConsumedCapacity})->then(sub { | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||
| 331 | # Only add the keys if they were requested | ||||||||||||||||||||||||||||||||
| 332 | 0 | for(qw(ConsumedCapacity)) { | |||||||||||||||||||||||||||||||
| 333 | 0 | my $k = shift; | |||||||||||||||||||||||||||||||
| 334 | 0 | ▶ | $result{$_} = $k if defined $k | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 335 | } | ||||||||||||||||||||||||||||||||
| 336 | 0 | return $self->done(get_item => \%result, $req, $tbl, $item); | |||||||||||||||||||||||||||||||
| 337 | 0 | ▶ | }, sub { | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||
| 338 | 0 | $self->fail(get_item => $req, @_) | |||||||||||||||||||||||||||||||
| 339 | }) | ||||||||||||||||||||||||||||||||
| 340 | 0 | ▶ | }, sub { | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=1.2
| |||||||||||||||||||||||||||||||||
| 341 | 1 | $self->fail(get_item => $req, @_) | |||||||||||||||||||||||||||||||
| 342 | }) | ||||||||||||||||||||||||||||||||
| 343 | 1 | ▶ | }, sub { | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 344 | 3 | $self->fail(get_item => $req, @_) | |||||||||||||||||||||||||||||||
| 345 | }) | ||||||||||||||||||||||||||||||||
| 346 | 4 | } | |||||||||||||||||||||||||||||||
| 347 | |||||||||||||||||||||||||||||||||
| 348 | =head2 update_item | ||||||||||||||||||||||||||||||||
| 349 | |||||||||||||||||||||||||||||||||
| 350 | UpdateItem (p. 103) | ||||||||||||||||||||||||||||||||
| 351 | |||||||||||||||||||||||||||||||||
| 352 | =cut | ||||||||||||||||||||||||||||||||
| 353 | |||||||||||||||||||||||||||||||||
| 354 | 0 | ▶ | sub update_item { | ||||||||||||||||||||||||||||||
|
Subroutine
update_item: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||
| 355 | 0 | my ($self, %args) = @_; | |||||||||||||||||||||||||||||||
| 356 | 0 | my $req = { %args }; | |||||||||||||||||||||||||||||||
| 357 | |||||||||||||||||||||||||||||||||
| 358 | 0 | my $name = delete $args{TableName}; | |||||||||||||||||||||||||||||||
| 359 | 0 | ▶ | $self->validate_table_state($name => 'ACTIVE')->then(sub { | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||
| 360 | 0 | my $tbl = $self->{table_map}{$name}; | |||||||||||||||||||||||||||||||
| 361 | 0 | ▶ | $tbl->validate_id_for_item_data($args{Key})->then(sub { | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||
| 362 | 0 | my $id = shift; | |||||||||||||||||||||||||||||||
| 363 | 0 | my %result; | |||||||||||||||||||||||||||||||
| 364 | my $item; | ||||||||||||||||||||||||||||||||
| 365 | 0 | ▶ | if(exists $self->{data}{$name}{$id}) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 366 | 0 | $item = $result{Item} = $self->{data}{$name}{$id} | |||||||||||||||||||||||||||||||
| 367 | } | ||||||||||||||||||||||||||||||||
| 368 | 0 | ▶ | return $self->consumed_capacity(delete $args{ReturnConsumedCapacity})->then(sub { | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||
| 369 | # Only add the keys if they were requested | ||||||||||||||||||||||||||||||||
| 370 | 0 | for(qw(ConsumedCapacity)) { | |||||||||||||||||||||||||||||||
| 371 | 0 | my $k = shift; | |||||||||||||||||||||||||||||||
| 372 | 0 | ▶ | $result{$_} = $k if defined $k | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 373 | } | ||||||||||||||||||||||||||||||||
| 374 | 0 | return $self->done(update_item => \%result, $req, $item); | |||||||||||||||||||||||||||||||
| 375 | }) | ||||||||||||||||||||||||||||||||
| 376 | 0 | }) | |||||||||||||||||||||||||||||||
| 377 | 0 | }) | |||||||||||||||||||||||||||||||
| 378 | 0 | } | |||||||||||||||||||||||||||||||
| 379 | |||||||||||||||||||||||||||||||||
| 380 | =head2 METHODS - Internal | ||||||||||||||||||||||||||||||||
| 381 | |||||||||||||||||||||||||||||||||
| 382 | The following methods are not part of the standard DynamoDB public API, | ||||||||||||||||||||||||||||||||
| 383 | so they are not recommended for use directly. | ||||||||||||||||||||||||||||||||
| 384 | |||||||||||||||||||||||||||||||||
| 385 | =cut | ||||||||||||||||||||||||||||||||
| 386 | |||||||||||||||||||||||||||||||||
| 387 | 133 | ▶ | sub bus { shift->{bus} //= Mixin::Event::Dispatch::Bus->new } | ||||||||||||||||||||||||||||||
|
Subroutine
bus: called CC=2 SCAR=7.2
Pod
undocumented
Condition66%2/3
+(shift())->{"bus"} //= "Mixin::Event::Dispatch::Bus"->new
MC/DC0%0/2
+(shift())->{"bus"} //= "Mixin::Event::Dispatch::Bus"->new
+(shift())->{"bus"}
"Mixin::Event::Dispatch::Bus"->new
Truth table66%2/3
A //= B
A= +(shift())->{"bus"}B= "Mixin::Event::Dispatch::Bus"->new
| |||||||||||||||||||||||||||||||||
| 388 | |||||||||||||||||||||||||||||||||
| 389 | =head2 add_table | ||||||||||||||||||||||||||||||||
| 390 | |||||||||||||||||||||||||||||||||
| 391 | Adds this table - called by L</create_table> if everything passes validation. | ||||||||||||||||||||||||||||||||
| 392 | |||||||||||||||||||||||||||||||||
| 393 | =cut | ||||||||||||||||||||||||||||||||
| 394 | |||||||||||||||||||||||||||||||||
| 395 | 12 | ▶ | sub add_table { | ||||||||||||||||||||||||||||||
|
Subroutine
add_table: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||
| 396 | 12 | my ($self, %args) = @_; | |||||||||||||||||||||||||||||||
| 397 | 12 | ▶ | $args{TableName} = delete $args{name} if exists $args{name}; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 398 | 12 | my $tbl = WebService::Amazon::DynamoDB::Server::Table->new( | |||||||||||||||||||||||||||||||
| 399 | %args | ||||||||||||||||||||||||||||||||
| 400 | ); | ||||||||||||||||||||||||||||||||
| 401 | 12 | push @{$self->{tables}}, $tbl; | |||||||||||||||||||||||||||||||
| 402 | 12 | $self->{table_map}{$tbl->name} = $tbl; | |||||||||||||||||||||||||||||||
| 403 | 12 | $tbl | |||||||||||||||||||||||||||||||
| 404 | } | ||||||||||||||||||||||||||||||||
| 405 | |||||||||||||||||||||||||||||||||
| 406 | =head2 drop_table | ||||||||||||||||||||||||||||||||
| 407 | |||||||||||||||||||||||||||||||||
| 408 | Drops the table - called to remove a table that was previously in 'DELETING' state. | ||||||||||||||||||||||||||||||||
| 409 | |||||||||||||||||||||||||||||||||
| 410 | =cut | ||||||||||||||||||||||||||||||||
| 411 | |||||||||||||||||||||||||||||||||
| 412 | 1 | ▶ | sub drop_table { | ||||||||||||||||||||||||||||||
|
Subroutine
drop_table: called CC=4 SCAR=14.2
Pod
documented
| |||||||||||||||||||||||||||||||||
| 413 | 1 | my ($self, %args) = @_; | |||||||||||||||||||||||||||||||
| 414 | 1 | ▶ | $args{TableName} = delete $args{name} if exists $args{name}; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 415 | 1 | my $name = $args{TableName}; | |||||||||||||||||||||||||||||||
| 416 | 1 | ▶ | extract_by { $_->name eq $name } @{$self->{tables}} or return Future->fail('table not found'); | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.1
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 417 | 1 | ▶ | delete $self->{table_map}{$name} or return Future->fail('table not found in map'); | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 418 | 1 | Future->done | |||||||||||||||||||||||||||||||
| 419 | } | ||||||||||||||||||||||||||||||||
| 420 | |||||||||||||||||||||||||||||||||
| 421 | =head2 return_values | ||||||||||||||||||||||||||||||||
| 422 | |||||||||||||||||||||||||||||||||
| 423 | Resolves to the attributes requested for this update. | ||||||||||||||||||||||||||||||||
| 424 | |||||||||||||||||||||||||||||||||
| 425 | =cut | ||||||||||||||||||||||||||||||||
| 426 | |||||||||||||||||||||||||||||||||
| 427 | 2 | ▶ | sub return_values { | ||||||||||||||||||||||||||||||
|
Subroutine
return_values: called CC=4 SCAR=14.5
Pod
documented
| |||||||||||||||||||||||||||||||||
| 428 | 2 | my ($self, $v) = @_; | |||||||||||||||||||||||||||||||
| 429 | 2 | ▶ | return Future->done(undef) if !defined($v) || $v eq 'NONE'; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
not defined $v or $v eq "NONE"
MC/DC50%1/2
not defined $v or $v eq "NONE"
not defined $v
$v eq "NONE"
Truth table66%2/3
not(A) or B
A= not defined $vB= $v eq "NONE"
| |||||||||||||||||||||||||||||||||
| 430 | 1 | ▶ | if($v eq 'ALL_OLD') { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 431 | 1 | return Future->done({ }) | |||||||||||||||||||||||||||||||
| 432 | } else { | ||||||||||||||||||||||||||||||||
| 433 | 0 | return Future->fail( | |||||||||||||||||||||||||||||||
| 434 | ValidationException => | ||||||||||||||||||||||||||||||||
| 435 | ) | ||||||||||||||||||||||||||||||||
| 436 | } | ||||||||||||||||||||||||||||||||
| 437 | } | ||||||||||||||||||||||||||||||||
| 438 | |||||||||||||||||||||||||||||||||
| 439 | =head2 consumed_capacity | ||||||||||||||||||||||||||||||||
| 440 | |||||||||||||||||||||||||||||||||
| 441 | Returns consumed capacity information if available. | ||||||||||||||||||||||||||||||||
| 442 | |||||||||||||||||||||||||||||||||
| 443 | =cut | ||||||||||||||||||||||||||||||||
| 444 | |||||||||||||||||||||||||||||||||
| 445 | 2 | ▶ | sub consumed_capacity { | ||||||||||||||||||||||||||||||
|
Subroutine
consumed_capacity: called CC=5 SCAR=27.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 446 | 2 | my ($self, $v) = @_; | |||||||||||||||||||||||||||||||
| 447 | 2 | ▶ | return Future->done(undef) if !defined($v) || $v eq 'NONE'; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
not defined $v or $v eq "NONE"
MC/DC0%0/2
not defined $v or $v eq "NONE"
not defined $v
$v eq "NONE"
Truth table33%1/3
not(A) or B
A= not defined $vB= $v eq "NONE"
| |||||||||||||||||||||||||||||||||
| 448 | 0 | ▶ | if($v eq 'INDEXES') { | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||
| 449 | 0 | return Future->done({ }) | |||||||||||||||||||||||||||||||
| 450 | } elsif($v eq 'TOTAL') { | ||||||||||||||||||||||||||||||||
| 451 | 0 | return Future->done({ }) | |||||||||||||||||||||||||||||||
| 452 | } else { | ||||||||||||||||||||||||||||||||
| 453 | 0 | return Future->fail( | |||||||||||||||||||||||||||||||
| 454 | ValidationException => | ||||||||||||||||||||||||||||||||
| 455 | ) | ||||||||||||||||||||||||||||||||
| 456 | } | ||||||||||||||||||||||||||||||||
| 457 | } | ||||||||||||||||||||||||||||||||
| 458 | |||||||||||||||||||||||||||||||||
| 459 | =head2 collection_metrics | ||||||||||||||||||||||||||||||||
| 460 | |||||||||||||||||||||||||||||||||
| 461 | Resolves to collection metrics information, if available. | ||||||||||||||||||||||||||||||||
| 462 | |||||||||||||||||||||||||||||||||
| 463 | =cut | ||||||||||||||||||||||||||||||||
| 464 | |||||||||||||||||||||||||||||||||
| 465 | 2 | ▶ | sub collection_metrics { | ||||||||||||||||||||||||||||||
|
Subroutine
collection_metrics: called CC=4 SCAR=21.7
Pod
documented
| |||||||||||||||||||||||||||||||||
| 466 | 2 | my ($self, $v) = @_; | |||||||||||||||||||||||||||||||
| 467 | 2 | ▶ | return Future->done(undef) if !defined($v) || $v eq 'NONE'; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
not defined $v or $v eq "NONE"
MC/DC0%0/2
not defined $v or $v eq "NONE"
not defined $v
$v eq "NONE"
Truth table33%1/3
not(A) or B
A= not defined $vB= $v eq "NONE"
| |||||||||||||||||||||||||||||||||
| 468 | 0 | ▶ | if($v eq 'SIZE') { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 469 | 0 | return Future->done({ }) | |||||||||||||||||||||||||||||||
| 470 | } else { | ||||||||||||||||||||||||||||||||
| 471 | 0 | return Future->fail( | |||||||||||||||||||||||||||||||
| 472 | ValidationException => | ||||||||||||||||||||||||||||||||
| 473 | ) | ||||||||||||||||||||||||||||||||
| 474 | } | ||||||||||||||||||||||||||||||||
| 475 | } | ||||||||||||||||||||||||||||||||
| 476 | |||||||||||||||||||||||||||||||||
| 477 | 9 | my %valid_table_status = map {; $_ => 1 } qw(CREATING DELETING UPDATING ACTIVE); | |||||||||||||||||||||||||||||||
| 478 | |||||||||||||||||||||||||||||||||
| 479 | =head2 table_status | ||||||||||||||||||||||||||||||||
| 480 | |||||||||||||||||||||||||||||||||
| 481 | Update or return current table status. | ||||||||||||||||||||||||||||||||
| 482 | |||||||||||||||||||||||||||||||||
| 483 | =cut | ||||||||||||||||||||||||||||||||
| 484 | |||||||||||||||||||||||||||||||||
| 485 | 11 | ▶ | sub table_status { | ||||||||||||||||||||||||||||||
|
Subroutine
table_status: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 486 | 11 | my ($self, $name, $status) = @_; | |||||||||||||||||||||||||||||||
| 487 | 11 | ▶ | if(defined $status) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 488 | 9 | ▶ | return Future->fail('bad status') unless exists $valid_table_status{$status}; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 489 | 9 | $self->{table_map}{$name}{TableStatus} = $status | |||||||||||||||||||||||||||||||
| 490 | } | ||||||||||||||||||||||||||||||||
| 491 | 11 | Future->done($self->{table_map}{$name}{TableStatus}); | |||||||||||||||||||||||||||||||
| 492 | } | ||||||||||||||||||||||||||||||||
| 493 | |||||||||||||||||||||||||||||||||
| 494 | =head2 have_table | ||||||||||||||||||||||||||||||||
| 495 | |||||||||||||||||||||||||||||||||
| 496 | Returns true if we have this table. | ||||||||||||||||||||||||||||||||
| 497 | |||||||||||||||||||||||||||||||||
| 498 | =cut | ||||||||||||||||||||||||||||||||
| 499 | |||||||||||||||||||||||||||||||||
| 500 | 39 | ▶ | sub have_table { | ||||||||||||||||||||||||||||||
|
Subroutine
have_table: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 501 | 39 | my ($self, $name) = @_; | |||||||||||||||||||||||||||||||
| 502 | 39 | return scalar exists $self->{table_map}{$name}; | |||||||||||||||||||||||||||||||
| 503 | } | ||||||||||||||||||||||||||||||||
| 504 | |||||||||||||||||||||||||||||||||
| 505 | =head2 validate_table_state | ||||||||||||||||||||||||||||||||
| 506 | |||||||||||||||||||||||||||||||||
| 507 | Raises various exceptions based on table state. | ||||||||||||||||||||||||||||||||
| 508 | |||||||||||||||||||||||||||||||||
| 509 | =cut | ||||||||||||||||||||||||||||||||
| 510 | |||||||||||||||||||||||||||||||||
| 511 | 26 | ▶ | sub validate_table_state { | ||||||||||||||||||||||||||||||
|
Subroutine
validate_table_state: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||||||
| 512 | 26 | my ($self, $name, @allowed) = @_; | |||||||||||||||||||||||||||||||
| 513 | |||||||||||||||||||||||||||||||||
| 514 | 26 | ▶ | return Future->fail( | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 515 | 'ResourceNotFoundException' | ||||||||||||||||||||||||||||||||
| 516 | ) unless defined $name; | ||||||||||||||||||||||||||||||||
| 517 | |||||||||||||||||||||||||||||||||
| 518 | 23 | ▶ | return Future->fail( | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 519 | 'ResourceNotFoundException' | ||||||||||||||||||||||||||||||||
| 520 | ) unless $self->have_table($name); | ||||||||||||||||||||||||||||||||
| 521 | |||||||||||||||||||||||||||||||||
| 522 | 18 | my $status = $self->{table_map}{$name}{TableStatus}; | |||||||||||||||||||||||||||||||
| 523 | 18 | ▶ | return Future->fail( | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 524 | 'ResourceInUseException' | ||||||||||||||||||||||||||||||||
| 525 | ) unless grep $status eq $_, @allowed; | ||||||||||||||||||||||||||||||||
| 526 | |||||||||||||||||||||||||||||||||
| 527 | 12 | Future->done; | |||||||||||||||||||||||||||||||
| 528 | } | ||||||||||||||||||||||||||||||||
| 529 | |||||||||||||||||||||||||||||||||
| 530 | 25 | ▶ | sub fail { | ||||||||||||||||||||||||||||||
|
Subroutine
fail: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 531 | 25 | my ($self, $sub, $req, $exception, @details) = @_; | |||||||||||||||||||||||||||||||
| 532 | 25 | ▶ | return Future->fail('invalid API name ' . $sub) unless exists $API_METHODS{$sub}; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 533 | 25 | my $f = Future->fail($exception => @details); | |||||||||||||||||||||||||||||||
| 534 | 25 | $self->bus->invoke_event($sub => $req, $f); | |||||||||||||||||||||||||||||||
| 535 | 25 | $self->bus->invoke_event(error => $req, $f); | |||||||||||||||||||||||||||||||
| 536 | 25 | $f | |||||||||||||||||||||||||||||||
| 537 | } | ||||||||||||||||||||||||||||||||
| 538 | |||||||||||||||||||||||||||||||||
| 539 | 9 | ▶ | use Carp qw(confess); | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 540 | 20 | ▶ | sub done { | ||||||||||||||||||||||||||||||
|
Subroutine
done: called CC=3 SCAR=11.2
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 541 | 20 | my ($self, $sub, $rslt, $req, @details) = @_; | |||||||||||||||||||||||||||||||
| 542 | 20 | ▶ | confess 'wtf' unless defined $sub; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 543 | 20 | ▶ | return Future->fail('invalid API name ' . $sub) unless exists $API_METHODS{$sub}; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 544 | 20 | my $f = Future->done($rslt); | |||||||||||||||||||||||||||||||
| 545 | 20 | $self->bus->invoke_event($sub => $req, $f, @details); | |||||||||||||||||||||||||||||||
| 546 | 20 | $f | |||||||||||||||||||||||||||||||
| 547 | } | ||||||||||||||||||||||||||||||||
| 548 | |||||||||||||||||||||||||||||||||
| 549 | 7 | ▶ | sub DESTROY { | ||||||||||||||||||||||||||||||
|
Subroutine
DESTROY: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 550 | 7 | my ($self) = @_; | |||||||||||||||||||||||||||||||
| 551 | 7 | $self->bus->invoke_event(destroy => ); | |||||||||||||||||||||||||||||||
| 552 | } | ||||||||||||||||||||||||||||||||
| 553 | |||||||||||||||||||||||||||||||||
| 554 | 9 | 1; | |||||||||||||||||||||||||||||||
| 555 | |||||||||||||||||||||||||||||||||
| 556 | __END__ | ||||||||||||||||||||||||||||||||