| 1 | package WebService::Amazon::DynamoDB::20120810; | ||||||||||||||||||||||
| 2 | 2 | $WebService::Amazon::DynamoDB::20120810::VERSION = '0.005'; | |||||||||||||||||||||
| 3 | 2 | ▶ | use strict; | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 4 | 2 | ▶ | use warnings; | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 5 | |||||||||||||||||||||||
| 6 | 2 | ▶ | use parent qw(WebService::Amazon::DynamoDB); | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 7 | |||||||||||||||||||||||
| 8 | =head1 NAME | ||||||||||||||||||||||
| 9 | |||||||||||||||||||||||
| 10 | WebService::Amazon::DynamoDB::20120810 - interact with DynamoDB using API version 20120810 | ||||||||||||||||||||||
| 11 | |||||||||||||||||||||||
| 12 | =head1 VERSION | ||||||||||||||||||||||
| 13 | |||||||||||||||||||||||
| 14 | version 0.005 | ||||||||||||||||||||||
| 15 | |||||||||||||||||||||||
| 16 | =head1 DESCRIPTION | ||||||||||||||||||||||
| 17 | |||||||||||||||||||||||
| 18 | =cut | ||||||||||||||||||||||
| 19 | |||||||||||||||||||||||
| 20 | 2 | ▶ | use Future; | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 21 | 2 | ▶ | use Future::Utils qw(try_repeat); | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 22 | 2 | ▶ | use POSIX qw(strftime); | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 23 | 2 | ▶ | use JSON::MaybeXS; | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 24 | 2 | ▶ | use Scalar::Util qw(reftype); | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 25 | 2 | ▶ | use B qw(svref_2object); | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 26 | 2 | ▶ | use HTTP::Request; | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 27 | |||||||||||||||||||||||
| 28 | 2 | ▶ | use WebService::Amazon::Signature; | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 29 | |||||||||||||||||||||||
| 30 | =head2 new | ||||||||||||||||||||||
| 31 | |||||||||||||||||||||||
| 32 | Instantiates the API object. | ||||||||||||||||||||||
| 33 | |||||||||||||||||||||||
| 34 | Expects the following named parameters: | ||||||||||||||||||||||
| 35 | |||||||||||||||||||||||
| 36 | =over 4 | ||||||||||||||||||||||
| 37 | |||||||||||||||||||||||
| 38 | =item * implementation - the object which provides a Future-returning C<request> method, | ||||||||||||||||||||||
| 39 | see L<WebService::Amazon::DynamoDB::NaHTTP> for example. | ||||||||||||||||||||||
| 40 | |||||||||||||||||||||||
| 41 | =item * uri - the base URI for constructing requests | ||||||||||||||||||||||
| 42 | |||||||||||||||||||||||
| 43 | =item * security - 'iam' or 'key' | ||||||||||||||||||||||
| 44 | |||||||||||||||||||||||
| 45 | =item * access_key - the access key for signing requests (only for security=key) | ||||||||||||||||||||||
| 46 | |||||||||||||||||||||||
| 47 | =item * secret_key - the secret key for signing requests (only for security=key) | ||||||||||||||||||||||
| 48 | |||||||||||||||||||||||
| 49 | =item * role - the role to use for requests (only for security=iam, usually autodetected from EC2 instance metadata) | ||||||||||||||||||||||
| 50 | |||||||||||||||||||||||
| 51 | =item * algorithm - which signing algorithm to use, default AWS4-HMAC-SHA256 | ||||||||||||||||||||||
| 52 | |||||||||||||||||||||||
| 53 | =back | ||||||||||||||||||||||
| 54 | |||||||||||||||||||||||
| 55 | =cut | ||||||||||||||||||||||
| 56 | |||||||||||||||||||||||
| 57 | 0 | ▶ | sub new { | ||||||||||||||||||||
|
Subroutine
new: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||
| 58 | 0 | my $class = shift; | |||||||||||||||||||||
| 59 | 0 | bless { @_ }, $class | |||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||
| 61 | |||||||||||||||||||||||
| 62 | 0 | ▶ | sub implementation { shift->{implementation} } | ||||||||||||||||||||
|
Subroutine
implementation: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||
| 63 | 0 | ▶ | sub host { shift->{host} } | ||||||||||||||||||||
|
Subroutine
host: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||
| 64 | 0 | ▶ | sub port { shift->{port} } | ||||||||||||||||||||
|
Subroutine
port: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||
| 65 | 0 | ▶ | sub algorithm { 'AWS4-HMAC-SHA256' } | ||||||||||||||||||||
|
Subroutine
algorithm: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||
| 66 | 0 | ▶ | sub access_key { shift->{access_key} } | ||||||||||||||||||||
|
Subroutine
access_key: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||
| 67 | 0 | ▶ | sub secret_key { shift->{secret_key} } | ||||||||||||||||||||
|
Subroutine
secret_key: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||
| 68 | 0 | ▶ | sub api_version { '20120810' } | ||||||||||||||||||||
|
Subroutine
api_version: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||
| 69 | 0 | ▶ | sub json { shift->{json} //= JSON::MaybeXS->new } | ||||||||||||||||||||
|
Subroutine
json: not called CC=2 SCAR=17.9
Pod
undocumented
Condition0%0/3
+(shift())->{"json"} //= "JSON::MaybeXS"->new
MC/DC0%0/2
+(shift())->{"json"} //= "JSON::MaybeXS"->new
+(shift())->{"json"}
"JSON::MaybeXS"->new
Truth table0%0/3
A //= B
A= +(shift())->{"json"}B= "JSON::MaybeXS"->new
| |||||||||||||||||||||||
| 70 | |||||||||||||||||||||||
| 71 | =head2 security_token | ||||||||||||||||||||||
| 72 | |||||||||||||||||||||||
| 73 | =cut | ||||||||||||||||||||||
| 74 | |||||||||||||||||||||||
| 75 | 0 | ▶ | sub security_token { shift->{security_token} } | ||||||||||||||||||||
|
Subroutine
security_token: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||
| 76 | |||||||||||||||||||||||
| 77 | |||||||||||||||||||||||
| 78 | =head2 create_table | ||||||||||||||||||||||
| 79 | |||||||||||||||||||||||
| 80 | Creates a new table. It may take some time before the table is marked | ||||||||||||||||||||||
| 81 | as active - use L</wait_for_table> to poll until the status changes. | ||||||||||||||||||||||
| 82 | |||||||||||||||||||||||
| 83 | Named parameters: | ||||||||||||||||||||||
| 84 | |||||||||||||||||||||||
| 85 | =over 4 | ||||||||||||||||||||||
| 86 | |||||||||||||||||||||||
| 87 | =item * table - the table name | ||||||||||||||||||||||
| 88 | |||||||||||||||||||||||
| 89 | =item * read_capacity - expected read capacity units (optional, default 5) | ||||||||||||||||||||||
| 90 | |||||||||||||||||||||||
| 91 | =item * write_capacity - expected write capacity units (optional, default 5) | ||||||||||||||||||||||
| 92 | |||||||||||||||||||||||
| 93 | =item * fields - an arrayref specifying the fields, in pairs of (name, type), | ||||||||||||||||||||||
| 94 | where type is N for numeric, S for string, SS for string sequence, B for binary | ||||||||||||||||||||||
| 95 | etc. | ||||||||||||||||||||||
| 96 | |||||||||||||||||||||||
| 97 | =item * primary - the primary keys as an arrayref of pairs indicating (name, type), | ||||||||||||||||||||||
| 98 | default type is hash so ['pkey'] would create a single HASH primary key | ||||||||||||||||||||||
| 99 | |||||||||||||||||||||||
| 100 | =back | ||||||||||||||||||||||
| 101 | |||||||||||||||||||||||
| 102 | =cut | ||||||||||||||||||||||
| 103 | |||||||||||||||||||||||
| 104 | 0 | ▶ | sub create_table { | ||||||||||||||||||||
|
Subroutine
create_table: not called CC=9 SCAR=45.0
Pod
documented
| |||||||||||||||||||||||
| 105 | 0 | my $self = shift; | |||||||||||||||||||||
| 106 | 0 | my %args = @_; | |||||||||||||||||||||
| 107 | my %payload = ( | ||||||||||||||||||||||
| 108 | TableName => $args{table}, | ||||||||||||||||||||||
| 109 | ProvisionedThroughput => { | ||||||||||||||||||||||
| 110 | ReadCapacityUnits => $args{read_capacity} || 5, | ||||||||||||||||||||||
| 111 | 0 | ▶ | WriteCapacityUnits => $args{write_capacity} || 5, | ||||||||||||||||||||
|
Condition0%0/4
$args{'read_capacity'} || 5
$args{'write_capacity'} || 5
MC/DC0%0/1
$args{'read_capacity'} || 5
$args{'read_capacity'}
MC/DC0%0/1
$args{'write_capacity'} || 5
$args{'write_capacity'}
Truth table0%0/2
A
A= $args{'read_capacity'}
Truth table0%0/2
A
A= $args{'write_capacity'}
| |||||||||||||||||||||||
| 112 | } | ||||||||||||||||||||||
| 113 | ); | ||||||||||||||||||||||
| 114 | 0 | my @fields = @{$args{fields}}; | |||||||||||||||||||||
| 115 | 0 | my %field; | |||||||||||||||||||||
| 116 | 0 | ▶ | while(my ($k, $type) = splice @fields, 0, 2) { | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 117 | 0 | $field{$k} = $type; | |||||||||||||||||||||
| 118 | 0 | ▶ | push @{$payload{AttributeDefinitions} }, { | ||||||||||||||||||||
|
Condition0%0/2
$type || 'S'
MC/DC0%0/1
$type || 'S'
$type
Truth table0%0/2
A
A= $type
| |||||||||||||||||||||||
| 119 | AttributeName => $k, | ||||||||||||||||||||||
| 120 | AttributeType => $type || 'S', | ||||||||||||||||||||||
| 121 | } | ||||||||||||||||||||||
| 122 | } | ||||||||||||||||||||||
| 123 | 0 | ▶ | my @primary = @{$args{primary} || []}; | ||||||||||||||||||||
|
Condition0%0/2
$args{'primary'} || []
MC/DC0%0/1
$args{'primary'} || []
$args{'primary'}
Truth table0%0/2
A
A= $args{'primary'}
| |||||||||||||||||||||||
| 124 | 0 | ▶ | while(my ($k, $type) = splice @primary, 0, 2) { | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 125 | 0 | ▶ | die "Unknown field $k" unless exists $field{$k}; | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 126 | 0 | ▶ | push @{$payload{KeySchema} }, { | ||||||||||||||||||||
|
Condition0%0/2
$type || 'HASH'
MC/DC0%0/1
$type || 'HASH'
$type
Truth table0%0/2
A
A= $type
| |||||||||||||||||||||||
| 127 | AttributeName => $k, | ||||||||||||||||||||||
| 128 | KeyType => $type || 'HASH', | ||||||||||||||||||||||
| 129 | } | ||||||||||||||||||||||
| 130 | } | ||||||||||||||||||||||
| 131 | $self->make_request( | ||||||||||||||||||||||
| 132 | target => 'CreateTable', | ||||||||||||||||||||||
| 133 | payload => \%payload, | ||||||||||||||||||||||
| 134 | 0 | ▶ | )->then(sub { | ||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||
| 135 | 0 | $self->_request(shift) | |||||||||||||||||||||
| 136 | }) | ||||||||||||||||||||||
| 137 | 0 | } | |||||||||||||||||||||
| 138 | |||||||||||||||||||||||
| 139 | =head2 describe_table | ||||||||||||||||||||||
| 140 | |||||||||||||||||||||||
| 141 | Describes the given table. | ||||||||||||||||||||||
| 142 | |||||||||||||||||||||||
| 143 | Takes a single named parameter: | ||||||||||||||||||||||
| 144 | |||||||||||||||||||||||
| 145 | =over 4 | ||||||||||||||||||||||
| 146 | |||||||||||||||||||||||
| 147 | =item * table - the table name | ||||||||||||||||||||||
| 148 | |||||||||||||||||||||||
| 149 | =back | ||||||||||||||||||||||
| 150 | |||||||||||||||||||||||
| 151 | and returns the table spec. | ||||||||||||||||||||||
| 152 | |||||||||||||||||||||||
| 153 | =cut | ||||||||||||||||||||||
| 154 | |||||||||||||||||||||||
| 155 | 0 | ▶ | sub describe_table { | ||||||||||||||||||||
|
Subroutine
describe_table: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||
| 156 | 0 | my $self = shift; | |||||||||||||||||||||
| 157 | 0 | my %args = @_; | |||||||||||||||||||||
| 158 | my %payload = ( | ||||||||||||||||||||||
| 159 | TableName => $args{table}, | ||||||||||||||||||||||
| 160 | 0 | ); | |||||||||||||||||||||
| 161 | $self->make_request( | ||||||||||||||||||||||
| 162 | target => 'DescribeTable', | ||||||||||||||||||||||
| 163 | payload => \%payload, | ||||||||||||||||||||||
| 164 | 0 | ▶ | )->then(sub { | ||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||
| 165 | $self->_request(shift)->transform( | ||||||||||||||||||||||
| 166 | # Sadly not the same key as used in DeleteTable | ||||||||||||||||||||||
| 167 | 0 | ▶ | done => sub { my $content = shift; $self->json->decode($content)->{Table}; } | ||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||
| 168 | 0 | ); | |||||||||||||||||||||
| 169 | }) | ||||||||||||||||||||||
| 170 | 0 | } | |||||||||||||||||||||
| 171 | |||||||||||||||||||||||
| 172 | =head2 delete_table | ||||||||||||||||||||||
| 173 | |||||||||||||||||||||||
| 174 | Delete a table entirely. | ||||||||||||||||||||||
| 175 | |||||||||||||||||||||||
| 176 | Takes a single named parameter: | ||||||||||||||||||||||
| 177 | |||||||||||||||||||||||
| 178 | =over 4 | ||||||||||||||||||||||
| 179 | |||||||||||||||||||||||
| 180 | =item * table - the table name | ||||||||||||||||||||||
| 181 | |||||||||||||||||||||||
| 182 | =back | ||||||||||||||||||||||
| 183 | |||||||||||||||||||||||
| 184 | =cut | ||||||||||||||||||||||
| 185 | |||||||||||||||||||||||
| 186 | 0 | ▶ | sub delete_table { | ||||||||||||||||||||
|
Subroutine
delete_table: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||
| 187 | 0 | my $self = shift; | |||||||||||||||||||||
| 188 | 0 | my %args = @_; | |||||||||||||||||||||
| 189 | my %payload = ( | ||||||||||||||||||||||
| 190 | TableName => $args{table}, | ||||||||||||||||||||||
| 191 | 0 | ); | |||||||||||||||||||||
| 192 | $self->make_request( | ||||||||||||||||||||||
| 193 | target => 'DeleteTable', | ||||||||||||||||||||||
| 194 | payload => \%payload, | ||||||||||||||||||||||
| 195 | 0 | ▶ | )->then(sub { | ||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||
| 196 | $self->_request(shift)->transform( | ||||||||||||||||||||||
| 197 | # Sadly not the same key as used in DescribeTable | ||||||||||||||||||||||
| 198 | 0 | ▶ | done => sub { my $content = shift; $self->json->decode($content)->{TableDescription} } | ||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||
| 199 | ) | ||||||||||||||||||||||
| 200 | 0 | }) | |||||||||||||||||||||
| 201 | 0 | } | |||||||||||||||||||||
| 202 | |||||||||||||||||||||||
| 203 | =head2 wait_for_table | ||||||||||||||||||||||
| 204 | |||||||||||||||||||||||
| 205 | Waits for the given table to be marked as active. | ||||||||||||||||||||||
| 206 | |||||||||||||||||||||||
| 207 | Takes a single named parameter: | ||||||||||||||||||||||
| 208 | |||||||||||||||||||||||
| 209 | =over 4 | ||||||||||||||||||||||
| 210 | |||||||||||||||||||||||
| 211 | =item * table - the table name | ||||||||||||||||||||||
| 212 | |||||||||||||||||||||||
| 213 | =back | ||||||||||||||||||||||
| 214 | |||||||||||||||||||||||
| 215 | =cut | ||||||||||||||||||||||
| 216 | |||||||||||||||||||||||
| 217 | 0 | ▶ | sub wait_for_table { | ||||||||||||||||||||
|
Subroutine
wait_for_table: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||
| 218 | 0 | my $self = shift; | |||||||||||||||||||||
| 219 | 0 | my %args = @_; | |||||||||||||||||||||
| 220 | 0 | ▶ | try_repeat { | ||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||
| 221 | 0 | $self->describe_table(%args) | |||||||||||||||||||||
| 222 | 0 | ▶ | } until => sub { | ||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||
| 223 | 0 | my $f = shift; | |||||||||||||||||||||
| 224 | 0 | my $status = $f->get->{TableStatus}; | |||||||||||||||||||||
| 225 | # warn "status: " . $status; | ||||||||||||||||||||||
| 226 | 0 | $status eq 'ACTIVE' | |||||||||||||||||||||
| 227 | 0 | }; | |||||||||||||||||||||
| 228 | } | ||||||||||||||||||||||
| 229 | |||||||||||||||||||||||
| 230 | =head2 each_table | ||||||||||||||||||||||
| 231 | |||||||||||||||||||||||
| 232 | Run code for all current tables. | ||||||||||||||||||||||
| 233 | |||||||||||||||||||||||
| 234 | Takes a coderef as the first parameter, will call this for each table found. | ||||||||||||||||||||||
| 235 | |||||||||||||||||||||||
| 236 | =cut | ||||||||||||||||||||||
| 237 | |||||||||||||||||||||||
| 238 | 0 | ▶ | sub each_table { | ||||||||||||||||||||
|
Subroutine
each_table: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||
| 239 | 0 | my $self = shift; | |||||||||||||||||||||
| 240 | 0 | my $code = shift; | |||||||||||||||||||||
| 241 | 0 | my %args = @_; | |||||||||||||||||||||
| 242 | 0 | my %payload; | |||||||||||||||||||||
| 243 | my $last_table; | ||||||||||||||||||||||
| 244 | 0 | ▶ | try_repeat { | ||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||
| 245 | 0 | ▶ | $payload{ExclusiveStartTableName} = $args{start} if defined $args{start}; | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 246 | 0 | ▶ | $payload{Limit} = $args{limit} if defined $args{limit}; | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 247 | $self->make_request( | ||||||||||||||||||||||
| 248 | target => 'ListTables', | ||||||||||||||||||||||
| 249 | payload => \%payload, | ||||||||||||||||||||||
| 250 | 0 | ▶ | )->then(sub { | ||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||
| 251 | 0 | $self->_request(shift) | |||||||||||||||||||||
| 252 | 0 | ▶ | })->on_done(sub { | ||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||
| 253 | 0 | my $rslt = shift; | |||||||||||||||||||||
| 254 | 0 | my $data = $self->json->decode($rslt); | |||||||||||||||||||||
| 255 | 0 | for my $tbl (@{$data->{TableNames}}) { | |||||||||||||||||||||
| 256 | 0 | $code->($tbl); | |||||||||||||||||||||
| 257 | } | ||||||||||||||||||||||
| 258 | 0 | $last_table = $data->{LastEvaluatedTableName}; | |||||||||||||||||||||
| 259 | 0 | $args{start} = $last_table; | |||||||||||||||||||||
| 260 | 0 | }); | |||||||||||||||||||||
| 261 | 0 | ▶ | } while => sub { | ||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||
| 262 | # warn "Checking @_ => $last_table\n"; | ||||||||||||||||||||||
| 263 | 0 | defined $last_table | |||||||||||||||||||||
| 264 | 0 | }; | |||||||||||||||||||||
| 265 | } | ||||||||||||||||||||||
| 266 | |||||||||||||||||||||||
| 267 | =head2 list_tables | ||||||||||||||||||||||
| 268 | |||||||||||||||||||||||
| 269 | Returns a L<Future> which will resolve with a list of all tables. | ||||||||||||||||||||||
| 270 | |||||||||||||||||||||||
| 271 | Takes no parameters. | ||||||||||||||||||||||
| 272 | |||||||||||||||||||||||
| 273 | $ddb->list_tables->on_done(sub { | ||||||||||||||||||||||
| 274 | my @tbl = @_; | ||||||||||||||||||||||
| 275 | print "Table: $_\n" for @tbl; | ||||||||||||||||||||||
| 276 | }); | ||||||||||||||||||||||
| 277 | |||||||||||||||||||||||
| 278 | =cut | ||||||||||||||||||||||
| 279 | |||||||||||||||||||||||
| 280 | 0 | ▶ | sub list_tables { | ||||||||||||||||||||
|
Subroutine
list_tables: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||
| 281 | 0 | my $self = shift; | |||||||||||||||||||||
| 282 | 0 | my @tbl; | |||||||||||||||||||||
| 283 | 0 | ▶ | $self->each_table(sub { | ||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||
| 284 | 0 | push @tbl, shift | |||||||||||||||||||||
| 285 | })->transform( | ||||||||||||||||||||||
| 286 | 0 | ▶ | done => sub { @tbl } | ||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||
| 287 | 0 | ); | |||||||||||||||||||||
| 288 | } | ||||||||||||||||||||||
| 289 | |||||||||||||||||||||||
| 290 | =head2 put_item | ||||||||||||||||||||||
| 291 | |||||||||||||||||||||||
| 292 | Writes a single item to the table. | ||||||||||||||||||||||
| 293 | |||||||||||||||||||||||
| 294 | Takes the following named parameters: | ||||||||||||||||||||||
| 295 | |||||||||||||||||||||||
| 296 | =over 4 | ||||||||||||||||||||||
| 297 | |||||||||||||||||||||||
| 298 | =item * table - the table name | ||||||||||||||||||||||
| 299 | |||||||||||||||||||||||
| 300 | =item * fields - the field spec, as a { key => value } hashref | ||||||||||||||||||||||
| 301 | |||||||||||||||||||||||
| 302 | =back | ||||||||||||||||||||||
| 303 | |||||||||||||||||||||||
| 304 | =cut | ||||||||||||||||||||||
| 305 | |||||||||||||||||||||||
| 306 | 0 | ▶ | sub put_item { | ||||||||||||||||||||
|
Subroutine
put_item: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||
| 307 | 0 | my $self = shift; | |||||||||||||||||||||
| 308 | 0 | my %args = @_; | |||||||||||||||||||||
| 309 | |||||||||||||||||||||||
| 310 | my %payload = ( | ||||||||||||||||||||||
| 311 | TableName => $args{table}, | ||||||||||||||||||||||
| 312 | 0 | ▶ | ReturnConsumedCapacity => $args{capacity} ? 'TOTAL' : 'NONE', | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 313 | ); | ||||||||||||||||||||||
| 314 | 0 | foreach my $k (keys %{$args{fields}}) { | |||||||||||||||||||||
| 315 | 0 | my $v = $args{fields}{$k}; | |||||||||||||||||||||
| 316 | 0 | $payload{Item}{$k} = { type_and_value($v) }; | |||||||||||||||||||||
| 317 | } | ||||||||||||||||||||||
| 318 | |||||||||||||||||||||||
| 319 | $self->make_request( | ||||||||||||||||||||||
| 320 | target => 'PutItem', | ||||||||||||||||||||||
| 321 | payload => \%payload, | ||||||||||||||||||||||
| 322 | 0 | ▶ | )->then(sub { | ||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||
| 323 | $self->_request(shift)->transform( | ||||||||||||||||||||||
| 324 | # Sadly not the same key as used in DeleteTable | ||||||||||||||||||||||
| 325 | 0 | ▶ | done => sub { $self->json->decode(shift)->{Table}; } | ||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||
| 326 | 0 | ); | |||||||||||||||||||||
| 327 | }) | ||||||||||||||||||||||
| 328 | 0 | } | |||||||||||||||||||||
| 329 | |||||||||||||||||||||||
| 330 | =head2 update_item | ||||||||||||||||||||||
| 331 | |||||||||||||||||||||||
| 332 | Updates a single item in the table. | ||||||||||||||||||||||
| 333 | |||||||||||||||||||||||
| 334 | Takes the following named parameters: | ||||||||||||||||||||||
| 335 | |||||||||||||||||||||||
| 336 | =over 4 | ||||||||||||||||||||||
| 337 | |||||||||||||||||||||||
| 338 | =item * table - the table name | ||||||||||||||||||||||
| 339 | |||||||||||||||||||||||
| 340 | =item * item - the item to update, as a{ key => value } hashref | ||||||||||||||||||||||
| 341 | |||||||||||||||||||||||
| 342 | =item * fields - the field spec, as a { key => value } hashref | ||||||||||||||||||||||
| 343 | |||||||||||||||||||||||
| 344 | =back | ||||||||||||||||||||||
| 345 | |||||||||||||||||||||||
| 346 | =cut | ||||||||||||||||||||||
| 347 | |||||||||||||||||||||||
| 348 | 0 | ▶ | sub update_item { | ||||||||||||||||||||
|
Subroutine
update_item: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||||||||||
| 349 | 0 | my $self = shift; | |||||||||||||||||||||
| 350 | 0 | my %args = @_; | |||||||||||||||||||||
| 351 | |||||||||||||||||||||||
| 352 | my %payload = ( | ||||||||||||||||||||||
| 353 | TableName => $args{table}, | ||||||||||||||||||||||
| 354 | 0 | ▶ | ReturnConsumedCapacity => $args{capacity} ? 'TOTAL' : 'NONE', | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 355 | ); | ||||||||||||||||||||||
| 356 | 0 | foreach my $k (keys %{$args{item}}) { | |||||||||||||||||||||
| 357 | 0 | my $v = $args{item}{$k}; | |||||||||||||||||||||
| 358 | 0 | $payload{Key}{$k} = { type_and_value($v) }; | |||||||||||||||||||||
| 359 | } | ||||||||||||||||||||||
| 360 | 0 | foreach my $k (keys %{$args{fields}}) { | |||||||||||||||||||||
| 361 | 0 | my $v = $args{fields}{$k}; | |||||||||||||||||||||
| 362 | $payload{AttributeUpdates}{$k} = { | ||||||||||||||||||||||
| 363 | 0 | ▶ | Action => $args{action} || 'PUT', | ||||||||||||||||||||
|
Condition0%0/2
$args{'action'} || 'PUT'
MC/DC0%0/1
$args{'action'} || 'PUT'
$args{'action'}
Truth table0%0/2
A
A= $args{'action'}
| |||||||||||||||||||||||
| 364 | Value => { type_and_value($v) } | ||||||||||||||||||||||
| 365 | }; | ||||||||||||||||||||||
| 366 | } | ||||||||||||||||||||||
| 367 | |||||||||||||||||||||||
| 368 | my $req = $self->make_request( | ||||||||||||||||||||||
| 369 | target => 'UpdateItem', | ||||||||||||||||||||||
| 370 | payload => \%payload, | ||||||||||||||||||||||
| 371 | 0 | ▶ | )->then(sub { | ||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||
| 372 | $self->_request(shift)->transform( | ||||||||||||||||||||||
| 373 | 0 | ▶ | done => sub { $self->json->decode(shift) } | ||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||
| 374 | 0 | ); | |||||||||||||||||||||
| 375 | }) | ||||||||||||||||||||||
| 376 | 0 | } | |||||||||||||||||||||
| 377 | |||||||||||||||||||||||
| 378 | =head2 delete_item | ||||||||||||||||||||||
| 379 | |||||||||||||||||||||||
| 380 | Deletes a single item from the table. | ||||||||||||||||||||||
| 381 | |||||||||||||||||||||||
| 382 | Takes the following named parameters: | ||||||||||||||||||||||
| 383 | |||||||||||||||||||||||
| 384 | =over 4 | ||||||||||||||||||||||
| 385 | |||||||||||||||||||||||
| 386 | =item * table - the table name | ||||||||||||||||||||||
| 387 | |||||||||||||||||||||||
| 388 | =item * item - the item to delete, as a { key => value } hashref | ||||||||||||||||||||||
| 389 | |||||||||||||||||||||||
| 390 | =back | ||||||||||||||||||||||
| 391 | |||||||||||||||||||||||
| 392 | =cut | ||||||||||||||||||||||
| 393 | |||||||||||||||||||||||
| 394 | 0 | ▶ | sub delete_item { | ||||||||||||||||||||
|
Subroutine
delete_item: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||
| 395 | 0 | my $self = shift; | |||||||||||||||||||||
| 396 | 0 | my %args = @_; | |||||||||||||||||||||
| 397 | |||||||||||||||||||||||
| 398 | my %payload = ( | ||||||||||||||||||||||
| 399 | TableName => $args{table}, | ||||||||||||||||||||||
| 400 | 0 | ▶ | ReturnConsumedCapacity => $args{capacity} ? 'TOTAL' : 'NONE', | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 401 | ); | ||||||||||||||||||||||
| 402 | 0 | foreach my $k (keys %{$args{item}}) { | |||||||||||||||||||||
| 403 | 0 | my $v = $args{item}{$k}; | |||||||||||||||||||||
| 404 | 0 | $payload{Key}{$k} = { type_and_value($v) }; | |||||||||||||||||||||
| 405 | } | ||||||||||||||||||||||
| 406 | |||||||||||||||||||||||
| 407 | my $req = $self->make_request( | ||||||||||||||||||||||
| 408 | target => 'DeleteItem', | ||||||||||||||||||||||
| 409 | payload => \%payload, | ||||||||||||||||||||||
| 410 | 0 | ▶ | )->then(sub { | ||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||
| 411 | $self->_request(shift)->transform( | ||||||||||||||||||||||
| 412 | 0 | ▶ | done => sub { $self->json->decode(shift) } | ||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||
| 413 | 0 | ); | |||||||||||||||||||||
| 414 | }) | ||||||||||||||||||||||
| 415 | 0 | } | |||||||||||||||||||||
| 416 | |||||||||||||||||||||||
| 417 | =head2 batch_get_item | ||||||||||||||||||||||
| 418 | |||||||||||||||||||||||
| 419 | Retrieve a batch of items from one or more tables. | ||||||||||||||||||||||
| 420 | |||||||||||||||||||||||
| 421 | Takes a coderef which will be called for each found item, followed by | ||||||||||||||||||||||
| 422 | these named parameters: | ||||||||||||||||||||||
| 423 | |||||||||||||||||||||||
| 424 | =over 4 | ||||||||||||||||||||||
| 425 | |||||||||||||||||||||||
| 426 | =item * items - the search spec, as { table => { attribute => 'value', ... }, ... } | ||||||||||||||||||||||
| 427 | |||||||||||||||||||||||
| 428 | =back | ||||||||||||||||||||||
| 429 | |||||||||||||||||||||||
| 430 | =cut | ||||||||||||||||||||||
| 431 | |||||||||||||||||||||||
| 432 | 0 | ▶ | sub batch_get_item { | ||||||||||||||||||||
|
Subroutine
batch_get_item: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||
| 433 | 0 | my $self = shift; | |||||||||||||||||||||
| 434 | 0 | my $code = shift; | |||||||||||||||||||||
| 435 | 0 | my %args = @_; | |||||||||||||||||||||
| 436 | my %payload = ( | ||||||||||||||||||||||
| 437 | 0 | ▶ | ReturnConsumedCapacity => $args{capacity} ? 'TOTAL' : 'NONE', | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 438 | ); | ||||||||||||||||||||||
| 439 | 0 | for my $tbl (keys %{$args{items}}) { | |||||||||||||||||||||
| 440 | 0 | my $item = $args{items}{$tbl}; | |||||||||||||||||||||
| 441 | 0 | my @keys = @{$item->{keys}}; | |||||||||||||||||||||
| 442 | 0 | $payload{RequestItems}{$tbl}{Keys} = []; | |||||||||||||||||||||
| 443 | 0 | ▶ | while(my ($k, $v) = splice @keys, 0, 2) { | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 444 | 0 | push @{$payload{RequestItems}{$tbl}{Keys}}, { | |||||||||||||||||||||
| 445 | $k => { | ||||||||||||||||||||||
| 446 | type_and_value($v) | ||||||||||||||||||||||
| 447 | } | ||||||||||||||||||||||
| 448 | }; | ||||||||||||||||||||||
| 449 | } | ||||||||||||||||||||||
| 450 | } | ||||||||||||||||||||||
| 451 | |||||||||||||||||||||||
| 452 | 0 | my $finished = 0; | |||||||||||||||||||||
| 453 | 0 | ▶ | try_repeat { | ||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||
| 454 | my $req = $self->make_request( | ||||||||||||||||||||||
| 455 | target => 'BatchGetItem', | ||||||||||||||||||||||
| 456 | payload => \%payload, | ||||||||||||||||||||||
| 457 | 0 | ▶ | )->then(sub { | ||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||
| 458 | 0 | $self->_request(shift) | |||||||||||||||||||||
| 459 | 0 | ▶ | })->on_done(sub { | ||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||
| 460 | 0 | my $rslt = shift; | |||||||||||||||||||||
| 461 | 0 | my $data = $self->json->decode($rslt); | |||||||||||||||||||||
| 462 | 0 | my @resp = %{$data->{Responses}}; | |||||||||||||||||||||
| 463 | # { Something => [ { Name => { S => 'text' } } ] } | ||||||||||||||||||||||
| 464 | 0 | ▶ | while(my ($k, $v) = splice @resp, 0, 2) { | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 465 | 0 | for my $entry (@$v) { | |||||||||||||||||||||
| 466 | $code->($k => { | ||||||||||||||||||||||
| 467 | 0 | map {; $_ => values %{$entry->{$_}} } keys %$entry | |||||||||||||||||||||
| 468 | }); | ||||||||||||||||||||||
| 469 | } | ||||||||||||||||||||||
| 470 | } | ||||||||||||||||||||||
| 471 | 0 | $args{RequestItems} = $data->{UnprocessedKeys}; | |||||||||||||||||||||
| 472 | 0 | ▶ | $finished = 1 unless keys %{$data->{UnprocessedKeys}}; | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 473 | 0 | }); | |||||||||||||||||||||
| 474 | 0 | ▶ | } until => sub { $finished }; | ||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||
| 475 | } | ||||||||||||||||||||||
| 476 | |||||||||||||||||||||||
| 477 | =head2 scan | ||||||||||||||||||||||
| 478 | |||||||||||||||||||||||
| 479 | Scan a table for values with an optional filter expression. | ||||||||||||||||||||||
| 480 | |||||||||||||||||||||||
| 481 | =cut | ||||||||||||||||||||||
| 482 | |||||||||||||||||||||||
| 483 | 0 | ▶ | sub scan { | ||||||||||||||||||||
|
Subroutine
scan: not called CC=6 SCAR=37.4
Pod
documented
| |||||||||||||||||||||||
| 484 | 0 | my $self = shift; | |||||||||||||||||||||
| 485 | 0 | my $code = shift; | |||||||||||||||||||||
| 486 | 0 | my %args = @_; | |||||||||||||||||||||
| 487 | my %payload = ( | ||||||||||||||||||||||
| 488 | TableName => $args{table}, | ||||||||||||||||||||||
| 489 | 0 | ▶ | ReturnConsumedCapacity => $args{capacity} ? 'TOTAL' : 'NONE', | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 490 | ); | ||||||||||||||||||||||
| 491 | 0 | $payload{AttributesToGet} = $args{fields}; | |||||||||||||||||||||
| 492 | 0 | ▶ | $payload{Limit} = $args{limit} if exists $args{limit}; | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 493 | 0 | my %filter; | |||||||||||||||||||||
| 494 | 0 | for my $f (@{$args{filter}}) { | |||||||||||||||||||||
| 495 | $filter{$f->{field}} = { | ||||||||||||||||||||||
| 496 | AttributeValueList => [ { | ||||||||||||||||||||||
| 497 | type_and_value($f->{value}) | ||||||||||||||||||||||
| 498 | } ], | ||||||||||||||||||||||
| 499 | 0 | ▶ | ComparisonOperator => $f->{compare} || 'EQ', | ||||||||||||||||||||
|
Condition0%0/2
$f->{'compare'} || 'EQ'
MC/DC0%0/1
$f->{'compare'} || 'EQ'
$f->{'compare'}
Truth table0%0/2
A
A= $f->{'compare'}
| |||||||||||||||||||||||
| 500 | } | ||||||||||||||||||||||
| 501 | } | ||||||||||||||||||||||
| 502 | 0 | ▶ | $payload{ScanFilter} = \%filter if %filter; | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 503 | 0 | my $finished = 0; | |||||||||||||||||||||
| 504 | 0 | my $count = 0; | |||||||||||||||||||||
| 505 | 0 | ▶ | try_repeat { | ||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||
| 506 | $self->make_request( | ||||||||||||||||||||||
| 507 | target => 'Scan', | ||||||||||||||||||||||
| 508 | payload => \%payload, | ||||||||||||||||||||||
| 509 | 0 | ▶ | )->then(sub { | ||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||
| 510 | 0 | $self->_request(shift) | |||||||||||||||||||||
| 511 | 0 | ▶ | })->on_done(sub { | ||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||
| 512 | 0 | my $rslt = shift; | |||||||||||||||||||||
| 513 | 0 | my $data = $self->json->decode($rslt); | |||||||||||||||||||||
| 514 | 0 | for my $entry (@{$data->{Items}}) { | |||||||||||||||||||||
| 515 | $code->({ | ||||||||||||||||||||||
| 516 | 0 | map {; $_ => values %{$entry->{$_}} } keys %$entry | |||||||||||||||||||||
| 517 | }); | ||||||||||||||||||||||
| 518 | } | ||||||||||||||||||||||
| 519 | 0 | $count += $data->{Count}; | |||||||||||||||||||||
| 520 | 0 | $args{ExclusiveStartKey} = $data->{LastEvaluatedKey}; | |||||||||||||||||||||
| 521 | 0 | ▶ | $finished = 1 unless keys %{$data->{LastEvaluatedKey}}; | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 522 | 0 | }); | |||||||||||||||||||||
| 523 | 0 | ▶ | } until => sub { $finished }; | ||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||
| 524 | } | ||||||||||||||||||||||
| 525 | |||||||||||||||||||||||
| 526 | =head1 METHODS - Internal | ||||||||||||||||||||||
| 527 | |||||||||||||||||||||||
| 528 | The following methods are intended for internal use and are documented | ||||||||||||||||||||||
| 529 | purely for completeness - for normal operations see L</METHODS> instead. | ||||||||||||||||||||||
| 530 | |||||||||||||||||||||||
| 531 | =cut | ||||||||||||||||||||||
| 532 | |||||||||||||||||||||||
| 533 | 0 | ▶ | sub scope { | ||||||||||||||||||||
|
Subroutine
scope: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||
| 534 | 0 | my $self = shift; | |||||||||||||||||||||
| 535 | 0 | join '/', strftime('%Y%m%d', gmtime), $self->region, qw(dynamodb aws4_request) | |||||||||||||||||||||
| 536 | } | ||||||||||||||||||||||
| 537 | |||||||||||||||||||||||
| 538 | 0 | ▶ | sub region { shift->{region} //= 'us-west-1' } | ||||||||||||||||||||
|
Subroutine
region: not called CC=2 SCAR=17.9
Pod
undocumented
Condition0%0/2
+(shift())->{"region"} //= "us-west-1"
MC/DC0%0/1
+(shift())->{"region"} //= "us-west-1"
+(shift())->{"region"}
Truth table0%0/2
A
A= +(shift())->{"region"}
| |||||||||||||||||||||||
| 539 | |||||||||||||||||||||||
| 540 | =head1 FUNCTIONS - Internal | ||||||||||||||||||||||
| 541 | |||||||||||||||||||||||
| 542 | =head2 type_for_value | ||||||||||||||||||||||
| 543 | |||||||||||||||||||||||
| 544 | Returns an appropriate type (N, S, SS etc.) for the given | ||||||||||||||||||||||
| 545 | value. | ||||||||||||||||||||||
| 546 | |||||||||||||||||||||||
| 547 | Rules are similar to L<JSON> - if you want numeric, numify (0+$value), | ||||||||||||||||||||||
| 548 | otherwise you'll get a string. | ||||||||||||||||||||||
| 549 | |||||||||||||||||||||||
| 550 | =cut | ||||||||||||||||||||||
| 551 | |||||||||||||||||||||||
| 552 | 0 | ▶ | sub type_for_value { | ||||||||||||||||||||
|
Subroutine
type_for_value: not called CC=8 SCAR=42.8
Pod
documented
| |||||||||||||||||||||||
| 553 | 0 | my $v = shift; | |||||||||||||||||||||
| 554 | 0 | ▶ | if(my $ref = reftype($v)) { | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 555 | # An array maps to a sequence | ||||||||||||||||||||||
| 556 | 0 | ▶ | if($ref eq 'ARRAY') { | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 557 | 0 | my $flags = B::svref_2object(\$v)->FLAGS; | |||||||||||||||||||||
| 558 | # Any refs mean we're sending binary data | ||||||||||||||||||||||
| 559 | 0 | ▶ | return 'BS' if grep ref($_), @$v; | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 560 | # Any stringified values => string data | ||||||||||||||||||||||
| 561 | 0 | ▶ | return 'SS' if grep $_ & B::SVp_POK, map B::svref_2object(\$_)->FLAGS, @$v; | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 562 | # Everything numeric? Send as a number | ||||||||||||||||||||||
| 563 | 0 | ▶ | return 'NS' if @$v == grep $_ & (B::SVp_IOK | B::SVp_NOK), map B::svref_2object(\$_)->FLAGS, @$v; | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 564 | # Default is a string sequence | ||||||||||||||||||||||
| 565 | 0 | return 'SS'; | |||||||||||||||||||||
| 566 | } else { | ||||||||||||||||||||||
| 567 | 0 | return 'B'; | |||||||||||||||||||||
| 568 | } | ||||||||||||||||||||||
| 569 | } else { | ||||||||||||||||||||||
| 570 | 0 | my $flags = B::svref_2object(\$v)->FLAGS; | |||||||||||||||||||||
| 571 | 0 | ▶ | return 'S' if $flags & B::SVp_POK; | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 572 | 0 | ▶ | return 'N' if $flags & (B::SVp_IOK | B::SVp_NOK); | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 573 | 0 | return 'S'; | |||||||||||||||||||||
| 574 | } | ||||||||||||||||||||||
| 575 | } | ||||||||||||||||||||||
| 576 | |||||||||||||||||||||||
| 577 | =head2 type_and_value | ||||||||||||||||||||||
| 578 | |||||||||||||||||||||||
| 579 | Returns a pair of (type, value), using L</type_for_value>. | ||||||||||||||||||||||
| 580 | |||||||||||||||||||||||
| 581 | =cut | ||||||||||||||||||||||
| 582 | |||||||||||||||||||||||
| 583 | 0 | ▶ | sub type_and_value { | ||||||||||||||||||||
|
Subroutine
type_and_value: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||
| 584 | 0 | my $v = shift; | |||||||||||||||||||||
| 585 | 0 | my $type = type_for_value($v); | |||||||||||||||||||||
| 586 | 0 | ▶ | return $type, "$v" unless my $ref = ref $v; | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 587 | 0 | ▶ | return $type, [ map "$_", @$v ] if $ref eq 'ARRAY'; | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 588 | 0 | ▶ | return $type, { map {; $_ => ''.$v->{$_} } keys %$v } if $ref eq 'HASH'; | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 589 | 0 | return $type, "$v"; | |||||||||||||||||||||
| 590 | } | ||||||||||||||||||||||
| 591 | |||||||||||||||||||||||
| 592 | 0 | ▶ | sub validate_table_name { | ||||||||||||||||||||
|
Subroutine
validate_table_name: not called CC=5 SCAR=34.0
Pod
undocumented
| |||||||||||||||||||||||
| 593 | 0 | my ($self, $name) = @_; | |||||||||||||||||||||
| 594 | 0 | ▶ | die 'Table name is undefined' unless defined $name; | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 595 | 0 | ▶ | die 'Name too short' if length($name) < 3; | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 596 | 0 | ▶ | die 'Name too long' if length($name) > 255; | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 597 | 0 | ▶ | die 'Invalid characters in name' if $name =~ /[^a-zA-Z0-9_.-]/; | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 598 | 0 | return 1; | |||||||||||||||||||||
| 599 | } | ||||||||||||||||||||||
| 600 | |||||||||||||||||||||||
| 601 | 2 | 1; | |||||||||||||||||||||
| 602 | |||||||||||||||||||||||
| 603 | __END__ | ||||||||||||||||||||||