| 1 | package Fey::Column; | ||||||||||
| 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 Scalar::Util qw( blessed weaken ); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | |||||||||||
| 11 | 26 | ▶ | use Fey::Column::Alias; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 12 | 26 | ▶ | use Fey::Exceptions qw( param_error object_state_error ); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 13 | 26 | ▶ | use Fey::Literal; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 14 | 26 | ▶ | use Fey::Table; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 15 | 26 | ▶ | use Fey::Table::Alias; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 16 | 26 | ▶ | use Fey::Types qw( | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 17 | Bool | ||||||||||
| 18 | DefaultValue | ||||||||||
| 19 | GenericTypeName | ||||||||||
| 20 | PosInteger | ||||||||||
| 21 | PosOrZeroInteger | ||||||||||
| 22 | Str | ||||||||||
| 23 | 26 | ); | |||||||||
| 24 | |||||||||||
| 25 | 26 | ▶ | use Moose 2.1200; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 26 | 26 | ▶ | use MooseX::SemiAffordanceAccessor 0.03; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 27 | 26 | ▶ | use MooseX::StrictConstructor 0.13; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 28 | |||||||||||
| 29 | 26 | with 'Fey::Role::ColumnLike'; | |||||||||
| 30 | |||||||||||
| 31 | 26 | with 'Fey::Role::MakesAliasObjects' => { | |||||||||
| 32 | self_param => 'column', | ||||||||||
| 33 | alias_class => 'Fey::Column::Alias', | ||||||||||
| 34 | }; | ||||||||||
| 35 | |||||||||||
| 36 | 26 | has 'id' => ( | |||||||||
| 37 | is => 'ro', | ||||||||||
| 38 | lazy_build => 1, | ||||||||||
| 39 | init_arg => undef, | ||||||||||
| 40 | clearer => '_clear_id', | ||||||||||
| 41 | ); | ||||||||||
| 42 | |||||||||||
| 43 | 26 | has 'name' => ( | |||||||||
| 44 | is => 'ro', | ||||||||||
| 45 | isa => Str, | ||||||||||
| 46 | required => 1, | ||||||||||
| 47 | ); | ||||||||||
| 48 | |||||||||||
| 49 | 26 | has 'generic_type' => ( | |||||||||
| 50 | is => 'ro', | ||||||||||
| 51 | isa => GenericTypeName, | ||||||||||
| 52 | lazy_build => 1, | ||||||||||
| 53 | ); | ||||||||||
| 54 | |||||||||||
| 55 | 26 | has type => ( | |||||||||
| 56 | is => 'ro', | ||||||||||
| 57 | isa => Str, | ||||||||||
| 58 | required => 1, | ||||||||||
| 59 | ); | ||||||||||
| 60 | |||||||||||
| 61 | 26 | has length => ( | |||||||||
| 62 | is => 'ro', | ||||||||||
| 63 | isa => PosInteger, | ||||||||||
| 64 | required => 0 | ||||||||||
| 65 | ); | ||||||||||
| 66 | |||||||||||
| 67 | # How to say that precision requires length as well? | ||||||||||
| 68 | 26 | has precision => ( | |||||||||
| 69 | is => 'ro', | ||||||||||
| 70 | isa => PosOrZeroInteger, | ||||||||||
| 71 | required => 0 | ||||||||||
| 72 | ); | ||||||||||
| 73 | |||||||||||
| 74 | 26 | has is_auto_increment => ( | |||||||||
| 75 | is => 'ro', | ||||||||||
| 76 | isa => Bool, | ||||||||||
| 77 | default => 0, | ||||||||||
| 78 | ); | ||||||||||
| 79 | |||||||||||
| 80 | 26 | has is_nullable => ( | |||||||||
| 81 | is => 'ro', | ||||||||||
| 82 | isa => Bool, | ||||||||||
| 83 | default => 0, | ||||||||||
| 84 | ); | ||||||||||
| 85 | |||||||||||
| 86 | 26 | has default => ( | |||||||||
| 87 | is => 'ro', | ||||||||||
| 88 | isa => DefaultValue, | ||||||||||
| 89 | coerce => 1, | ||||||||||
| 90 | ); | ||||||||||
| 91 | |||||||||||
| 92 | 26 | has 'table' => ( | |||||||||
| 93 | is => 'rw', | ||||||||||
| 94 | does => 'Fey::Role::TableLike', | ||||||||||
| 95 | weak_ref => 1, | ||||||||||
| 96 | predicate => 'has_table', | ||||||||||
| 97 | writer => '_set_table', | ||||||||||
| 98 | clearer => '_clear_table', | ||||||||||
| 99 | ); | ||||||||||
| 100 | |||||||||||
| 101 | 676 | ▶ | after '_set_table', '_clear_table' => sub { $_[0]->_clear_id() }; | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 102 | |||||||||||
| 103 | 26 | with 'Fey::Role::Named'; | |||||||||
| 104 | |||||||||||
| 105 | { | ||||||||||
| 106 | 26 | my @TypesRe = ( | |||||||||
| 107 | [ text => qr/(?:text|char(?:acter)?)\b/xism ], | ||||||||||
| 108 | [ blob => qr/blob\b|bytea\b/xism ], | ||||||||||
| 109 | |||||||||||
| 110 | # The year type comes from MySQL | ||||||||||
| 111 | [ integer => qr/(?:int(?:eger)?\d*|year)\b/xism ], | ||||||||||
| 112 | [ float => qr/(?:float\d*|decimal|real|double|money|numeric)\b/xism ], | ||||||||||
| 113 | |||||||||||
| 114 | # MySQL's timestamp is not always a datetime, it depends on | ||||||||||
| 115 | # the length of the column, but this is the best _guess_. | ||||||||||
| 116 | [ datetime => qr/datetime\b|^timestamp/xism ], | ||||||||||
| 117 | [ date => qr/date\b/xism ], | ||||||||||
| 118 | [ time => qr/^time|time\b/xism ], | ||||||||||
| 119 | [ boolean => qr/\bbool/xism ], | ||||||||||
| 120 | ); | ||||||||||
| 121 | |||||||||||
| 122 | 62 | ▶ | sub _build_generic_type { | ||||||||
|
Subroutine
_build_generic_type: called CC=3 SCAR=11.0
| |||||||||||
| 123 | 62 | my $self = shift; | |||||||||
| 124 | 62 | my $type = $self->type(); | |||||||||
| 125 | |||||||||||
| 126 | 62 | for my $p (@TypesRe) { | |||||||||
| 127 | 259 | ▶ | return $p->[0] if $type =~ /$p->[1]/; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 128 | } | ||||||||||
| 129 | |||||||||||
| 130 | 9 | return 'other'; | |||||||||
| 131 | } | ||||||||||
| 132 | } | ||||||||||
| 133 | |||||||||||
| 134 | 26 | ▶ | sub _clone { | ||||||||
|
Subroutine
_clone: called CC=1 SCAR=0.0
| |||||||||||
| 135 | 8 | my $self = shift; | |||||||||
| 136 | |||||||||||
| 137 | 8 | my %clone = %{$self}; | |||||||||
| 138 | |||||||||||
| 139 | 8 | return bless \%clone, ref $self; | |||||||||
| 140 | } | ||||||||||
| 141 | |||||||||||
| 142 | 1 | ▶ | sub is_alias { return 0 } | ||||||||
|
Subroutine
is_alias: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 143 | |||||||||||
| 144 | 151 | ▶ | sub sql { | ||||||||
|
Subroutine
sql: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 145 | 151 | my $self = shift; | |||||||||
| 146 | 151 | my $dbh = shift; | |||||||||
| 147 | |||||||||||
| 148 | 151 | return $dbh->quote_identifier( | |||||||||
| 149 | undef, | ||||||||||
| 150 | $self->_containing_table_name_or_alias(), | ||||||||||
| 151 | $self->name(), | ||||||||||
| 152 | ); | ||||||||||
| 153 | } | ||||||||||
| 154 | |||||||||||
| 155 | 37 | ▶ | sub sql_with_alias { goto &sql } | ||||||||
|
Subroutine
sql_with_alias: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 156 | |||||||||||
| 157 | 100 | ▶ | sub sql_or_alias { goto &sql } | ||||||||
|
Subroutine
sql_or_alias: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 158 | |||||||||||
| 159 | 3 | ▶ | sub _build_id { | ||||||||
|
Subroutine
_build_id: called CC=2 SCAR=6.9
| |||||||||||
| 160 | 3 | my $self = shift; | |||||||||
| 161 | |||||||||||
| 162 | 3 | my $table = $self->table(); | |||||||||
| 163 | |||||||||||
| 164 | 3 | ▶ | object_state_error | ||||||||
|
Branch: 1 branch
| |||||||||||
| 165 | 'The id attribute cannot be determined for a column object which has no table.' | ||||||||||
| 166 | unless $table; | ||||||||||
| 167 | |||||||||||
| 168 | 1 | return $table->id() . q{.} . $self->name(); | |||||||||
| 169 | } | ||||||||||
| 170 | |||||||||||
| 171 | 26 | __PACKAGE__->meta()->make_immutable(); | |||||||||
| 172 | |||||||||||
| 173 | 26 | 1; | |||||||||
| 174 | |||||||||||
| 175 | # ABSTRACT: Represents a column | ||||||||||
| 176 | |||||||||||
| 177 | __END__ | ||||||||||