| 1 | package Fey::Table::Alias; | ||||||||||||
| 2 | |||||||||||||
| 3 | 26 | ▶ | use strict; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 4 | 26 | ▶ | use warnings; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 5 | 26 | ▶ | use namespace::autoclean; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 6 | |||||||||||||
| 7 | 26 | our $VERSION = '0.44'; | |||||||||||
| 8 | |||||||||||||
| 9 | 26 | ▶ | use Fey::Exceptions qw(param_error); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 10 | 26 | ▶ | use Fey::Table; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 11 | 26 | ▶ | use Fey::Types qw( Column HashRef Str Table ); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 12 | |||||||||||||
| 13 | 26 | ▶ | use Moose 2.1200; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 14 | 26 | ▶ | use MooseX::Params::Validate 0.21 qw( pos_validated_list ); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 15 | 26 | ▶ | use MooseX::SemiAffordanceAccessor 0.03; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 16 | 26 | ▶ | use MooseX::StrictConstructor 0.13; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 17 | |||||||||||||
| 18 | 26 | with 'Fey::Role::TableLike'; | |||||||||||
| 19 | |||||||||||||
| 20 | 26 | has 'id' => ( | |||||||||||
| 21 | is => 'ro', | ||||||||||||
| 22 | lazy_build => 1, | ||||||||||||
| 23 | init_arg => undef, | ||||||||||||
| 24 | ); | ||||||||||||
| 25 | |||||||||||||
| 26 | 26 | has 'table' => ( | |||||||||||
| 27 | is => 'ro', | ||||||||||||
| 28 | isa => Table, | ||||||||||||
| 29 | handles => [ 'schema', 'name' ], | ||||||||||||
| 30 | ); | ||||||||||||
| 31 | |||||||||||||
| 32 | 26 | has 'alias_name' => ( | |||||||||||
| 33 | is => 'ro', | ||||||||||||
| 34 | isa => Str, | ||||||||||||
| 35 | lazy_build => 1, | ||||||||||||
| 36 | ); | ||||||||||||
| 37 | |||||||||||||
| 38 | has '_columns' => ( | ||||||||||||
| 39 | traits => ['Hash'], | ||||||||||||
| 40 | is => 'bare', | ||||||||||||
| 41 | isa => HashRef [Column], | ||||||||||||
| 42 | 7 | ▶ | default => sub { {} }, | ||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||
| 43 | 26 | handles => { | |||||||||||
| 44 | _get_column => 'get', | ||||||||||||
| 45 | _set_column => 'set', | ||||||||||||
| 46 | _has_column => 'exists', | ||||||||||||
| 47 | }, | ||||||||||||
| 48 | init_arg => undef, | ||||||||||||
| 49 | ); | ||||||||||||
| 50 | |||||||||||||
| 51 | 26 | with 'Fey::Role::Named'; | |||||||||||
| 52 | |||||||||||||
| 53 | { | ||||||||||||
| 54 | 26 | my %Numbers; | |||||||||||
| 55 | |||||||||||||
| 56 | 3 | ▶ | sub _build_alias_name { | ||||||||||
|
Subroutine
_build_alias_name: called CC=2 SCAR=6.9
| |||||||||||||
| 57 | 3 | my $self = shift; | |||||||||||
| 58 | |||||||||||||
| 59 | 3 | my $name = $self->name(); | |||||||||||
| 60 | 3 | ▶ | $Numbers{$name} ||= 0; | ||||||||||
|
Condition100%2/2
$Numbers{$name} ||= 0
MC/DC100%1/1
$Numbers{$name} ||= 0
$Numbers{$name}
Truth table100%2/2
A
A= $Numbers{$name}
| |||||||||||||
| 61 | |||||||||||||
| 62 | 3 | return $name . ++$Numbers{$name}; | |||||||||||
| 63 | } | ||||||||||||
| 64 | } | ||||||||||||
| 65 | |||||||||||||
| 66 | 26 | ▶ | sub column { | ||||||||||
|
Subroutine
column: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||
| 67 | 11 | my $self = shift; | |||||||||||
| 68 | 11 | my ($name) = pos_validated_list( \@_, { isa => 'Str' } ); | |||||||||||
| 69 | |||||||||||||
| 70 | 11 | ▶ | return $self->_get_column($name) | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 71 | if $self->_has_column($name); | ||||||||||||
| 72 | |||||||||||||
| 73 | 8 | ▶ | my $col = $self->table()->column($name) | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 74 | or return; | ||||||||||||
| 75 | |||||||||||||
| 76 | 7 | my $clone = $col->_clone(); | |||||||||||
| 77 | 7 | $clone->_set_table($self); | |||||||||||
| 78 | |||||||||||||
| 79 | 7 | $self->_set_column( $name => $clone ); | |||||||||||
| 80 | |||||||||||||
| 81 | 7 | return $clone; | |||||||||||
| 82 | } | ||||||||||||
| 83 | |||||||||||||
| 84 | 5 | ▶ | sub columns { | ||||||||||
|
Subroutine
columns: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||
| 85 | 5 | my $self = shift; | |||||||||||
| 86 | |||||||||||||
| 87 | 5 | ▶ | my @cols = @_ ? @_ : map { $_->name() } $self->table()->columns(); | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 88 | |||||||||||||
| 89 | 5 | return map { $self->column($_) } @cols; | |||||||||||
| 90 | } | ||||||||||||
| 91 | |||||||||||||
| 92 | # Making this an attribute would be a hassle since we'd need to reset | ||||||||||||
| 93 | # it whenever the associated table's keys changed. | ||||||||||||
| 94 | 1 | ▶ | sub primary_key { | ||||||||||
|
Subroutine
primary_key: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 95 | return [ | ||||||||||||
| 96 | $_[0]->columns( | ||||||||||||
| 97 | 1 | map { $_->name() } @{ $_[0]->table()->primary_key() } | |||||||||||
| 98 | ) | ||||||||||||
| 99 | ]; | ||||||||||||
| 100 | } | ||||||||||||
| 101 | |||||||||||||
| 102 | 5 | ▶ | sub is_alias {1} | ||||||||||
|
Subroutine
is_alias: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 103 | |||||||||||||
| 104 | 0 | ▶ | sub sql_with_alias { | ||||||||||
|
Subroutine
sql_with_alias: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||
| 105 | 0 | return ( $_[1]->quote_identifier( $_[0]->table()->name() ) . ' AS ' | |||||||||||
| 106 | . $_[1]->quote_identifier( $_[0]->alias_name() ) ); | ||||||||||||
| 107 | } | ||||||||||||
| 108 | |||||||||||||
| 109 | 1 | ▶ | sub _build_id { $_[0]->alias_name() } | ||||||||||
|
Subroutine
_build_id: called CC=1 SCAR=0.0
| |||||||||||||
| 110 | |||||||||||||
| 111 | 26 | __PACKAGE__->meta()->make_immutable(); | |||||||||||
| 112 | |||||||||||||
| 113 | 26 | 1; | |||||||||||
| 114 | |||||||||||||
| 115 | # ABSTRACT: Represents an alias for a table | ||||||||||||
| 116 | |||||||||||||
| 117 | __END__ | ||||||||||||