| 1 | package DBIx::Skinny::InflateColumn::DateTime::Auto; | ||||||||||||||||||||
| 2 | |||||||||||||||||||||
| 3 | 7 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 4 | 7 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 5 | |||||||||||||||||||||
| 6 | 7 | ▶ | use DateTime; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 7 | 7 | ▶ | use DateTime::Format::Strptime; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 8 | 7 | ▶ | use DateTime::Format::MySQL; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 9 | 7 | ▶ | use DateTime::TimeZone; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 10 | |||||||||||||||||||||
| 11 | 7 | ▶ | sub import { | ||||||||||||||||||
|
Subroutine
import: called CC=6 SCAR=24.2
| |||||||||||||||||||||
| 12 | 7 | my $class = shift; | |||||||||||||||||||
| 13 | 7 | my %args = @_; | |||||||||||||||||||
| 14 | 7 | ▶ | my $timezone = $args{time_zone} || DateTime::TimeZone->new(name => 'local'); | ||||||||||||||||||
|
Condition66%2/3
$args{'time_zone'} || 'DateTime::TimeZone'->new('name', 'local')
MC/DC0%0/2
$args{'time_zone'} || 'DateTime::TimeZone'->new('name', 'local')
$args{'time_zone'}
'DateTime::TimeZone'->new('name', 'local')
Truth table33%1/3
A || B
A= $args{'time_zone'}B= 'DateTime::TimeZone'->new('name', 'local')
| |||||||||||||||||||||
| 15 | 1 | ▶ | my @rules = @{ $args{rules} || [qr/^.+_at$/, qr/^.+_on$/] }; | ||||||||||||||||||
|
Condition50%1/2
$args{'rules'} || [qr/^.+_at$/, qr/^.+_on$/]
MC/DC0%0/1
$args{'rules'} || [qr/^.+_at$/, qr/^.+_on$/]
$args{'rules'}
Truth table50%1/2
A
A= $args{'rules'}
| |||||||||||||||||||||
| 16 | 1 | ▶ | my @auto_insert_rules = @{ $args{auto_insert_rules} || [qr/^created_at$/, qr/^created_on$/, qr/^updated_at$/, qr/^updated_on$/] }; | ||||||||||||||||||
|
Condition50%1/2
$args{'auto_insert_rules'} || [qr/^created_at$/, qr/^created_on$/, qr/^updated_at$/, qr/^updated_on$/]
MC/DC0%0/1
$args{'auto_insert_rules'} || [qr/^created_at$/, qr/^created_on$/, qr/^updated_at$/, qr/^updated_on$/]
$args{'auto_insert_rules'}
Truth table50%1/2
A
A= $args{'auto_insert_rules'}
| |||||||||||||||||||||
| 17 | 1 | ▶ | my @auto_update_rules = @{ $args{auto_update_rules} || [qr/^updated_at$/, qr/^updated_on$/] }; | ||||||||||||||||||
|
Condition50%1/2
$args{'auto_update_rules'} || [qr/^updated_at$/, qr/^updated_on$/]
MC/DC0%0/1
$args{'auto_update_rules'} || [qr/^updated_at$/, qr/^updated_on$/]
$args{'auto_update_rules'}
Truth table50%1/2
A
A= $args{'auto_update_rules'}
| |||||||||||||||||||||
| 18 | |||||||||||||||||||||
| 19 | 1 | my $schema = caller; | |||||||||||||||||||
| 20 | 1 | for my $rule ( @rules ) { | |||||||||||||||||||
| 21 | 1 | ▶ | $schema->inflate_rules->{ $rule }->{ inflate } = sub { | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.4
| |||||||||||||||||||||
| 22 | 1 | ▶ | my $value = shift or return; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 23 | 1 | ▶ | return $value if ref $value eq 'DateTime'; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 24 | 1 | my $dt = DateTime::Format::Strptime->new( | |||||||||||||||||||
| 25 | pattern => '%Y-%m-%d %H:%M:%S', | ||||||||||||||||||||
| 26 | time_zone => $timezone, | ||||||||||||||||||||
| 27 | )->parse_datetime($value); | ||||||||||||||||||||
| 28 | 1 | return DateTime->from_object( object => $dt ); | |||||||||||||||||||
| 29 | 2 | }; | |||||||||||||||||||
| 30 | 0 | ▶ | $schema->inflate_rules->{ $rule }->{ deflate } = sub { | ||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||
| 31 | 0 | my $value = shift; | |||||||||||||||||||
| 32 | 0 | return DateTime::Format::MySQL->format_datetime($value); | |||||||||||||||||||
| 33 | 2 | }; | |||||||||||||||||||
| 34 | } | ||||||||||||||||||||
| 35 | 1 | my $schema_info = $schema->schema_info; | |||||||||||||||||||
| 36 | 1 | ▶ | push @{ $schema->common_triggers->{ pre_insert } }, sub { | ||||||||||||||||||
|
Subroutine
__ANON__: not called CC=4 SCAR=28.1
| |||||||||||||||||||||
| 37 | 0 | my ($self, $args, $table) = @_; | |||||||||||||||||||
| 38 | 0 | my $columns = $schema_info->{ $table }->{ columns }; | |||||||||||||||||||
| 39 | 0 | my $now = DateTime->now(time_zone => $timezone); | |||||||||||||||||||
| 40 | |||||||||||||||||||||
| 41 | COLUMN_LOOP: | ||||||||||||||||||||
| 42 | 0 | for my $column ( grep { !$args->{$_} } @{$columns} ) { | |||||||||||||||||||
| 43 | RULE_LOOP: | ||||||||||||||||||||
| 44 | 0 | for my $rule ( @auto_insert_rules ) { | |||||||||||||||||||
| 45 | 0 | ▶ | if ( $column =~ m/$rule/ ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 46 | 0 | $args->{$column} = $now; | |||||||||||||||||||
| 47 | 0 | last RULE_LOOP; | |||||||||||||||||||
| 48 | } | ||||||||||||||||||||
| 49 | } | ||||||||||||||||||||
| 50 | } | ||||||||||||||||||||
| 51 | 1 | }; | |||||||||||||||||||
| 52 | 1 | ▶ | push @{ $schema->common_triggers->{ pre_update } }, sub { | ||||||||||||||||||
|
Subroutine
__ANON__: not called CC=4 SCAR=28.1
| |||||||||||||||||||||
| 53 | 0 | my ($self, $args, $table) = @_; | |||||||||||||||||||
| 54 | 0 | my $columns = $schema_info->{ $table }->{ columns }; | |||||||||||||||||||
| 55 | 0 | my $now = DateTime->now(time_zone => $timezone); | |||||||||||||||||||
| 56 | |||||||||||||||||||||
| 57 | COLUMN_LOOP: | ||||||||||||||||||||
| 58 | 0 | for my $column ( grep { !$args->{$_} } @{$columns} ) { | |||||||||||||||||||
| 59 | RULE_LOOP: | ||||||||||||||||||||
| 60 | 0 | for my $rule ( @auto_update_rules ) { | |||||||||||||||||||
| 61 | 0 | ▶ | if ( $column =~ m/$rule/ ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 62 | 0 | $args->{$column} = $now; | |||||||||||||||||||
| 63 | 0 | last RULE_LOOP; | |||||||||||||||||||
| 64 | } | ||||||||||||||||||||
| 65 | } | ||||||||||||||||||||
| 66 | } | ||||||||||||||||||||
| 67 | 1 | }; | |||||||||||||||||||
| 68 | } | ||||||||||||||||||||
| 69 | |||||||||||||||||||||
| 70 | 7 | 1; | |||||||||||||||||||
| 71 | __END__ | ||||||||||||||||||||