| 1 | package SQL::Translator::Schema::Field; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||
| 3 | =pod | ||||||||||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||||||||||
| 5 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||
| 7 | SQL::Translator::Schema::Field - SQL::Translator field object | ||||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||
| 9 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||||
| 11 | use SQL::Translator::Schema::Field; | ||||||||||||||||||||||||||||||||||||||||||
| 12 | my $field = SQL::Translator::Schema::Field->new( | ||||||||||||||||||||||||||||||||||||||||||
| 13 | name => 'foo', | ||||||||||||||||||||||||||||||||||||||||||
| 14 | table => $table, | ||||||||||||||||||||||||||||||||||||||||||
| 15 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||
| 17 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||||||
| 19 | C<SQL::Translator::Schema::Field> is the field object. | ||||||||||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||||||||||
| 21 | =head1 METHODS | ||||||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||||||
| 23 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||||||||
| 25 | 76 | ▶ | use Moo; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 26 | 76 | ▶ | use SQL::Translator::Schema::Constants; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 27 | 76 | ▶ | use SQL::Translator::Types qw(schema_obj); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 28 | 76 | ▶ | use SQL::Translator::Utils qw(parse_list_arg ex2err throw carp_ro); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 29 | 76 | ▶ | use Sub::Quote qw(quote_sub); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 30 | 76 | ▶ | use Scalar::Util (); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||||||||
| 32 | 76 | extends 'SQL::Translator::Schema::Object'; | |||||||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||||||||
| 34 | 76 | our $VERSION = '1.66'; | |||||||||||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||||||||||||
| 36 | # Stringify to our name, being careful not to pass any args through so we don't | ||||||||||||||||||||||||||||||||||||||||||
| 37 | # accidentally set it to undef. We also have to tweak bool so the object is | ||||||||||||||||||||||||||||||||||||||||||
| 38 | # still true when it doesn't have a name (which shouldn't happen!). | ||||||||||||||||||||||||||||||||||||||||||
| 39 | use overload | ||||||||||||||||||||||||||||||||||||||||||
| 40 | 4460 | ▶ | '""' => sub { shift->name }, | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 41 | 8746 | ▶ | 'bool' => sub { $_[0]->name || $_[0] }, | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.6
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 42 | 76 | fallback => 1, | |||||||||||||||||||||||||||||||||||||||||
| 43 | 76 | ; | |||||||||||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||||||||||
| 45 | 76 | ▶ | use DBI qw(:sql_types); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||||||||
| 47 | # Mapping from string to sql constant | ||||||||||||||||||||||||||||||||||||||||||
| 48 | 76 | our %type_mapping = ( | |||||||||||||||||||||||||||||||||||||||||
| 49 | integer => SQL_INTEGER, | ||||||||||||||||||||||||||||||||||||||||||
| 50 | int => SQL_INTEGER, | ||||||||||||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||||||||||
| 52 | tinyint => SQL_TINYINT, | ||||||||||||||||||||||||||||||||||||||||||
| 53 | smallint => SQL_SMALLINT, | ||||||||||||||||||||||||||||||||||||||||||
| 54 | bigint => SQL_BIGINT, | ||||||||||||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||||||||||||
| 56 | double => SQL_DOUBLE, | ||||||||||||||||||||||||||||||||||||||||||
| 57 | 'double precision' => SQL_DOUBLE, | ||||||||||||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||||||||||||
| 59 | decimal => SQL_DECIMAL, | ||||||||||||||||||||||||||||||||||||||||||
| 60 | dec => SQL_DECIMAL, | ||||||||||||||||||||||||||||||||||||||||||
| 61 | numeric => SQL_NUMERIC, | ||||||||||||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||||||||||||
| 63 | real => SQL_REAL, | ||||||||||||||||||||||||||||||||||||||||||
| 64 | float => SQL_FLOAT, | ||||||||||||||||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||||||||||||||||
| 66 | bit => SQL_BIT, | ||||||||||||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||||||||||||
| 68 | date => SQL_DATE, | ||||||||||||||||||||||||||||||||||||||||||
| 69 | datetime => SQL_DATETIME, | ||||||||||||||||||||||||||||||||||||||||||
| 70 | timestamp => SQL_TIMESTAMP, | ||||||||||||||||||||||||||||||||||||||||||
| 71 | time => SQL_TIME, | ||||||||||||||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||||||||||||
| 73 | char => SQL_CHAR, | ||||||||||||||||||||||||||||||||||||||||||
| 74 | varchar => SQL_VARCHAR, | ||||||||||||||||||||||||||||||||||||||||||
| 75 | binary => SQL_BINARY, | ||||||||||||||||||||||||||||||||||||||||||
| 76 | varbinary => SQL_VARBINARY, | ||||||||||||||||||||||||||||||||||||||||||
| 77 | tinyblob => SQL_BLOB, | ||||||||||||||||||||||||||||||||||||||||||
| 78 | blob => SQL_BLOB, | ||||||||||||||||||||||||||||||||||||||||||
| 79 | text => SQL_LONGVARCHAR | ||||||||||||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||||||||||||
| 81 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||||||||||||
| 83 | 76 | has _numeric_sql_data_types => (is => 'lazy'); | |||||||||||||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||||||||||||
| 85 | 205 | ▶ | sub _build__numeric_sql_data_types { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_build__numeric_sql_data_types: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 86 | return { | ||||||||||||||||||||||||||||||||||||||||||
| 87 | 205 | map { $_ => 1 } ( | |||||||||||||||||||||||||||||||||||||||||
| 88 | SQL_INTEGER, SQL_TINYINT, SQL_SMALLINT, SQL_BIGINT, SQL_DOUBLE, SQL_NUMERIC, SQL_DECIMAL, SQL_FLOAT, SQL_REAL | ||||||||||||||||||||||||||||||||||||||||||
| 89 | ) | ||||||||||||||||||||||||||||||||||||||||||
| 90 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||||||||||||
| 93 | =head2 new | ||||||||||||||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||||||||||||||
| 95 | Object constructor. | ||||||||||||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||||||||||||
| 97 | my $field = SQL::Translator::Schema::Field->new( | ||||||||||||||||||||||||||||||||||||||||||
| 98 | name => 'foo', | ||||||||||||||||||||||||||||||||||||||||||
| 99 | table => $table, | ||||||||||||||||||||||||||||||||||||||||||
| 100 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||||||||||||||||
| 102 | =head2 comments | ||||||||||||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||||||||||||
| 104 | Get or set the comments on a field. May be called several times to | ||||||||||||||||||||||||||||||||||||||||||
| 105 | set and it will accumulate the comments. Called in an array context, | ||||||||||||||||||||||||||||||||||||||||||
| 106 | returns each comment individually; called in a scalar context, returns | ||||||||||||||||||||||||||||||||||||||||||
| 107 | all the comments joined on newlines. | ||||||||||||||||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||||||||||||||||
| 109 | $field->comments('foo'); | ||||||||||||||||||||||||||||||||||||||||||
| 110 | $field->comments('bar'); | ||||||||||||||||||||||||||||||||||||||||||
| 111 | print join( ', ', $field->comments ); # prints "foo, bar" | ||||||||||||||||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||||||||||||||||
| 113 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||||||||||||||||
| 115 | 76 | has comments => ( | |||||||||||||||||||||||||||||||||||||||||
| 116 | is => 'rw', | ||||||||||||||||||||||||||||||||||||||||||
| 117 | coerce => quote_sub(q{ ref($_[0]) eq 'ARRAY' ? $_[0] : [$_[0]] }), | ||||||||||||||||||||||||||||||||||||||||||
| 118 | default => quote_sub(q{ [] }), | ||||||||||||||||||||||||||||||||||||||||||
| 119 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||||||||||||||||
| 121 | 982 | ▶ | around comments => sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=5 SCAR=16.2
| |||||||||||||||||||||||||||||||||||||||||||
| 122 | 982 | my $orig = shift; | |||||||||||||||||||||||||||||||||||||||||
| 123 | 982 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||||||||||||||||
| 125 | 982 | for my $arg (@_) { | |||||||||||||||||||||||||||||||||||||||||
| 126 | 1 | ▶ | $arg = $arg->[0] if ref $arg; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 127 | 1 | ▶ | push @{ $self->$orig }, $arg if $arg; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 128 | } | ||||||||||||||||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||||||||||||||||
| 130 | return wantarray | ||||||||||||||||||||||||||||||||||||||||||
| 131 | 7 | ? @{ $self->$orig } | |||||||||||||||||||||||||||||||||||||||||
| 132 | 982 | ▶ | : join("\n", @{ $self->$orig }); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 133 | 76 | }; | |||||||||||||||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||||||||||||||||
| 135 | =head2 data_type | ||||||||||||||||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||||||||||||||||
| 137 | Get or set the field's data type. | ||||||||||||||||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||||||||||||||||
| 139 | my $data_type = $field->data_type('integer'); | ||||||||||||||||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||||||||||||||||
| 141 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||||||||||||||||
| 143 | 76 | has data_type => (is => 'rw', default => quote_sub(q{ '' })); | |||||||||||||||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||||||||||||||||
| 145 | =head2 sql_data_type | ||||||||||||||||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||||||||||||||||
| 147 | Constant from DBI package representing this data type. See L<DBI/DBI Constants> | ||||||||||||||||||||||||||||||||||||||||||
| 148 | for more details. | ||||||||||||||||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||||||||||||||||
| 150 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||||||||||||||||
| 152 | 76 | has sql_data_type => (is => 'rw', lazy => 1, builder => 1); | |||||||||||||||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||||||||||||||||
| 154 | 325 | ▶ | sub _build_sql_data_type { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_build_sql_data_type: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 155 | 325 | ▶ | $type_mapping{ lc $_[0]->data_type } || SQL_UNKNOWN_TYPE; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 156 | } | ||||||||||||||||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||||||||||||||||
| 158 | =head2 default_value | ||||||||||||||||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||||||||||||||||
| 160 | Get or set the field's default value. Will return undef if not defined | ||||||||||||||||||||||||||||||||||||||||||
| 161 | and could return the empty string (it's a valid default value), so don't | ||||||||||||||||||||||||||||||||||||||||||
| 162 | assume an error like other methods. | ||||||||||||||||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||||||||||||||||
| 164 | my $default = $field->default_value('foo'); | ||||||||||||||||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||||||||||||||||
| 166 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||||||||||||||||
| 168 | 76 | has default_value => (is => 'rw'); | |||||||||||||||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||||||||||||||||
| 170 | =head2 foreign_key_reference | ||||||||||||||||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||||||||||||||||
| 172 | Get or set the field's foreign key reference; | ||||||||||||||||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||||||||||||||||
| 174 | my $constraint = $field->foreign_key_reference( $constraint ); | ||||||||||||||||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||||||||||||||||
| 176 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||||||||||||||||
| 178 | 76 | has foreign_key_reference => ( | |||||||||||||||||||||||||||||||||||||||||
| 179 | is => 'rw', | ||||||||||||||||||||||||||||||||||||||||||
| 180 | predicate => '_has_foreign_key_reference', | ||||||||||||||||||||||||||||||||||||||||||
| 181 | isa => schema_obj('Constraint'), | ||||||||||||||||||||||||||||||||||||||||||
| 182 | weak_ref => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 183 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||||||||||||||||
| 185 | 45 | ▶ | around foreign_key_reference => sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||
| 186 | 45 | my $orig = shift; | |||||||||||||||||||||||||||||||||||||||||
| 187 | 45 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||||||||||||||||
| 189 | 45 | ▶ | if (my $arg = shift) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 190 | 14 | ▶ | return $self->error('Foreign key reference for ', $self->name, 'already defined') | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 191 | if $self->_has_foreign_key_reference; | ||||||||||||||||||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||||||||||||||||
| 193 | 14 | return ex2err($orig, $self, $arg); | |||||||||||||||||||||||||||||||||||||||||
| 194 | } | ||||||||||||||||||||||||||||||||||||||||||
| 195 | 31 | $self->$orig; | |||||||||||||||||||||||||||||||||||||||||
| 196 | 76 | }; | |||||||||||||||||||||||||||||||||||||||||
| 197 | |||||||||||||||||||||||||||||||||||||||||||
| 198 | =head2 is_auto_increment | ||||||||||||||||||||||||||||||||||||||||||
| 199 | |||||||||||||||||||||||||||||||||||||||||||
| 200 | Get or set the field's C<is_auto_increment> attribute. | ||||||||||||||||||||||||||||||||||||||||||
| 201 | |||||||||||||||||||||||||||||||||||||||||||
| 202 | my $is_auto = $field->is_auto_increment(1); | ||||||||||||||||||||||||||||||||||||||||||
| 203 | |||||||||||||||||||||||||||||||||||||||||||
| 204 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||||||||||||||||
| 206 | 76 | has is_auto_increment => ( | |||||||||||||||||||||||||||||||||||||||||
| 207 | is => 'rw', | ||||||||||||||||||||||||||||||||||||||||||
| 208 | coerce => quote_sub(q{ $_[0] ? 1 : 0 }), | ||||||||||||||||||||||||||||||||||||||||||
| 209 | builder => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 210 | lazy => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 211 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||||||||||||||||||||
| 213 | 714 | ▶ | sub _build_is_auto_increment { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_build_is_auto_increment: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||||||||||||||||
| 214 | 714 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 215 | |||||||||||||||||||||||||||||||||||||||||||
| 216 | 714 | ▶ | if (my $table = $self->table) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 217 | 709 | ▶ | if (my $schema = $table->schema) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 218 | 687 | ▶ | if ( $schema->database eq 'PostgreSQL' | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$schema->database eq "PostgreSQL" and $self->data_type eq "serial"
MC/DC50%1/2
$schema->database eq "PostgreSQL" and $self->data_type eq "serial"
$schema->database eq "PostgreSQL"
$self->data_type eq "serial"
Truth table66%2/3
A and B
A= $schema->database eq "PostgreSQL"B= $self->data_type eq "serial"
| |||||||||||||||||||||||||||||||||||||||||||
| 219 | && $self->data_type eq 'serial') { | ||||||||||||||||||||||||||||||||||||||||||
| 220 | 1 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 221 | } | ||||||||||||||||||||||||||||||||||||||||||
| 222 | } | ||||||||||||||||||||||||||||||||||||||||||
| 223 | } | ||||||||||||||||||||||||||||||||||||||||||
| 224 | 713 | return 0; | |||||||||||||||||||||||||||||||||||||||||
| 225 | } | ||||||||||||||||||||||||||||||||||||||||||
| 226 | |||||||||||||||||||||||||||||||||||||||||||
| 227 | =head2 is_foreign_key | ||||||||||||||||||||||||||||||||||||||||||
| 228 | |||||||||||||||||||||||||||||||||||||||||||
| 229 | Returns whether or not the field is a foreign key. | ||||||||||||||||||||||||||||||||||||||||||
| 230 | |||||||||||||||||||||||||||||||||||||||||||
| 231 | my $is_fk = $field->is_foreign_key; | ||||||||||||||||||||||||||||||||||||||||||
| 232 | |||||||||||||||||||||||||||||||||||||||||||
| 233 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 234 | |||||||||||||||||||||||||||||||||||||||||||
| 235 | 76 | has is_foreign_key => ( | |||||||||||||||||||||||||||||||||||||||||
| 236 | is => 'rw', | ||||||||||||||||||||||||||||||||||||||||||
| 237 | coerce => quote_sub(q{ $_[0] ? 1 : 0 }), | ||||||||||||||||||||||||||||||||||||||||||
| 238 | builder => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 239 | lazy => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 240 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 241 | |||||||||||||||||||||||||||||||||||||||||||
| 242 | 175 | ▶ | sub _build_is_foreign_key { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_build_is_foreign_key: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||||||||||||||||
| 243 | 175 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 244 | |||||||||||||||||||||||||||||||||||||||||||
| 245 | 175 | ▶ | if (my $table = $self->table) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 246 | 175 | for my $c ($table->get_constraints) { | |||||||||||||||||||||||||||||||||||||||||
| 247 | 369 | ▶ | if ($c->type eq FOREIGN_KEY) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 248 | 93 | my %fields = map { $_, 1 } $c->fields; | |||||||||||||||||||||||||||||||||||||||||
| 249 | 93 | ▶ | if ($fields{ $self->name }) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 250 | 14 | $self->foreign_key_reference($c); | |||||||||||||||||||||||||||||||||||||||||
| 251 | 14 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 252 | } | ||||||||||||||||||||||||||||||||||||||||||
| 253 | } | ||||||||||||||||||||||||||||||||||||||||||
| 254 | } | ||||||||||||||||||||||||||||||||||||||||||
| 255 | } | ||||||||||||||||||||||||||||||||||||||||||
| 256 | 161 | return 0; | |||||||||||||||||||||||||||||||||||||||||
| 257 | } | ||||||||||||||||||||||||||||||||||||||||||
| 258 | |||||||||||||||||||||||||||||||||||||||||||
| 259 | =head2 is_nullable | ||||||||||||||||||||||||||||||||||||||||||
| 260 | |||||||||||||||||||||||||||||||||||||||||||
| 261 | Get or set whether the field can be null. If not defined, then | ||||||||||||||||||||||||||||||||||||||||||
| 262 | returns "1" (assumes the field can be null). The argument is evaluated | ||||||||||||||||||||||||||||||||||||||||||
| 263 | by Perl for True or False, so the following are equivalent: | ||||||||||||||||||||||||||||||||||||||||||
| 264 | |||||||||||||||||||||||||||||||||||||||||||
| 265 | $is_nullable = $field->is_nullable(0); | ||||||||||||||||||||||||||||||||||||||||||
| 266 | $is_nullable = $field->is_nullable(''); | ||||||||||||||||||||||||||||||||||||||||||
| 267 | $is_nullable = $field->is_nullable('0'); | ||||||||||||||||||||||||||||||||||||||||||
| 268 | |||||||||||||||||||||||||||||||||||||||||||
| 269 | While this is technically a field constraint, it's probably easier to | ||||||||||||||||||||||||||||||||||||||||||
| 270 | represent this as an attribute of the field. In order keep things | ||||||||||||||||||||||||||||||||||||||||||
| 271 | consistent, any other constraint on the field (unique, primary, and | ||||||||||||||||||||||||||||||||||||||||||
| 272 | foreign keys; checks) are represented as table constraints. | ||||||||||||||||||||||||||||||||||||||||||
| 273 | |||||||||||||||||||||||||||||||||||||||||||
| 274 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 275 | |||||||||||||||||||||||||||||||||||||||||||
| 276 | 76 | has is_nullable => ( | |||||||||||||||||||||||||||||||||||||||||
| 277 | is => 'rw', | ||||||||||||||||||||||||||||||||||||||||||
| 278 | coerce => quote_sub(q{ $_[0] ? 1 : 0 }), | ||||||||||||||||||||||||||||||||||||||||||
| 279 | default => quote_sub(q{ 1 }), | ||||||||||||||||||||||||||||||||||||||||||
| 280 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 281 | |||||||||||||||||||||||||||||||||||||||||||
| 282 | 1922 | ▶ | around is_nullable => sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||
| 283 | 1922 | my ($orig, $self, $arg) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 284 | |||||||||||||||||||||||||||||||||||||||||||
| 285 | 1922 | ▶ | $self->$orig($self->is_primary_key ? 0 : defined $arg ? $arg : ()); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 286 | 76 | }; | |||||||||||||||||||||||||||||||||||||||||
| 287 | |||||||||||||||||||||||||||||||||||||||||||
| 288 | =head2 is_primary_key | ||||||||||||||||||||||||||||||||||||||||||
| 289 | |||||||||||||||||||||||||||||||||||||||||||
| 290 | Get or set the field's C<is_primary_key> attribute. Does not create | ||||||||||||||||||||||||||||||||||||||||||
| 291 | a table constraint (should it?). | ||||||||||||||||||||||||||||||||||||||||||
| 292 | |||||||||||||||||||||||||||||||||||||||||||
| 293 | my $is_pk = $field->is_primary_key(1); | ||||||||||||||||||||||||||||||||||||||||||
| 294 | |||||||||||||||||||||||||||||||||||||||||||
| 295 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 296 | |||||||||||||||||||||||||||||||||||||||||||
| 297 | 76 | has is_primary_key => ( | |||||||||||||||||||||||||||||||||||||||||
| 298 | is => 'rw', | ||||||||||||||||||||||||||||||||||||||||||
| 299 | coerce => quote_sub(q{ $_[0] ? 1 : 0 }), | ||||||||||||||||||||||||||||||||||||||||||
| 300 | lazy => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 301 | builder => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 302 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 303 | |||||||||||||||||||||||||||||||||||||||||||
| 304 | 674 | ▶ | sub _build_is_primary_key { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_build_is_primary_key: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||
| 305 | 674 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 306 | |||||||||||||||||||||||||||||||||||||||||||
| 307 | 674 | ▶ | if (my $table = $self->table) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 308 | 672 | ▶ | if (my $pk = $table->primary_key) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 309 | 541 | my %fields = map { $_, 1 } $pk->fields; | |||||||||||||||||||||||||||||||||||||||||
| 310 | 541 | ▶ | return $fields{ $self->name } || 0; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$fields{$self->name} || 0
MC/DC0%0/1
$fields{$self->name} || 0
$fields{$self->name}
Truth table50%1/2
A
A= $fields{$self->name}
| |||||||||||||||||||||||||||||||||||||||||||
| 311 | } | ||||||||||||||||||||||||||||||||||||||||||
| 312 | } | ||||||||||||||||||||||||||||||||||||||||||
| 313 | 133 | return 0; | |||||||||||||||||||||||||||||||||||||||||
| 314 | } | ||||||||||||||||||||||||||||||||||||||||||
| 315 | |||||||||||||||||||||||||||||||||||||||||||
| 316 | =head2 is_unique | ||||||||||||||||||||||||||||||||||||||||||
| 317 | |||||||||||||||||||||||||||||||||||||||||||
| 318 | Determine whether the field has a UNIQUE constraint or not. | ||||||||||||||||||||||||||||||||||||||||||
| 319 | |||||||||||||||||||||||||||||||||||||||||||
| 320 | my $is_unique = $field->is_unique; | ||||||||||||||||||||||||||||||||||||||||||
| 321 | |||||||||||||||||||||||||||||||||||||||||||
| 322 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 323 | |||||||||||||||||||||||||||||||||||||||||||
| 324 | 76 | has is_unique => (is => 'lazy', init_arg => undef); | |||||||||||||||||||||||||||||||||||||||||
| 325 | |||||||||||||||||||||||||||||||||||||||||||
| 326 | 76 | around is_unique => carp_ro('is_unique'); | |||||||||||||||||||||||||||||||||||||||||
| 327 | |||||||||||||||||||||||||||||||||||||||||||
| 328 | 90 | ▶ | sub _build_is_unique { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_build_is_unique: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||||||||||||||||
| 329 | 90 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 330 | |||||||||||||||||||||||||||||||||||||||||||
| 331 | 90 | ▶ | if (my $table = $self->table) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 332 | 90 | for my $c ($table->get_constraints) { | |||||||||||||||||||||||||||||||||||||||||
| 333 | 202 | ▶ | if ($c->type eq UNIQUE) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 334 | 77 | my %fields = map { $_, 1 } $c->fields; | |||||||||||||||||||||||||||||||||||||||||
| 335 | 77 | ▶ | if ($fields{ $self->name }) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 336 | 10 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 337 | } | ||||||||||||||||||||||||||||||||||||||||||
| 338 | } | ||||||||||||||||||||||||||||||||||||||||||
| 339 | } | ||||||||||||||||||||||||||||||||||||||||||
| 340 | } | ||||||||||||||||||||||||||||||||||||||||||
| 341 | 80 | return 0; | |||||||||||||||||||||||||||||||||||||||||
| 342 | } | ||||||||||||||||||||||||||||||||||||||||||
| 343 | |||||||||||||||||||||||||||||||||||||||||||
| 344 | 320 | ▶ | sub is_valid { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
is_valid: called CC=4 SCAR=14.6
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 345 | |||||||||||||||||||||||||||||||||||||||||||
| 346 | =pod | ||||||||||||||||||||||||||||||||||||||||||
| 347 | |||||||||||||||||||||||||||||||||||||||||||
| 348 | =head2 is_valid | ||||||||||||||||||||||||||||||||||||||||||
| 349 | |||||||||||||||||||||||||||||||||||||||||||
| 350 | Determine whether the field is valid or not. | ||||||||||||||||||||||||||||||||||||||||||
| 351 | |||||||||||||||||||||||||||||||||||||||||||
| 352 | my $ok = $field->is_valid; | ||||||||||||||||||||||||||||||||||||||||||
| 353 | |||||||||||||||||||||||||||||||||||||||||||
| 354 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 355 | |||||||||||||||||||||||||||||||||||||||||||
| 356 | 320 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 357 | 320 | ▶ | return $self->error('No name') unless $self->name; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 358 | 320 | ▶ | return $self->error('No data type') unless $self->data_type; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 359 | 320 | ▶ | return $self->error('No table object') unless $self->table; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 360 | 320 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 361 | } | ||||||||||||||||||||||||||||||||||||||||||
| 362 | |||||||||||||||||||||||||||||||||||||||||||
| 363 | =head2 name | ||||||||||||||||||||||||||||||||||||||||||
| 364 | |||||||||||||||||||||||||||||||||||||||||||
| 365 | Get or set the field's name. | ||||||||||||||||||||||||||||||||||||||||||
| 366 | |||||||||||||||||||||||||||||||||||||||||||
| 367 | my $name = $field->name('foo'); | ||||||||||||||||||||||||||||||||||||||||||
| 368 | |||||||||||||||||||||||||||||||||||||||||||
| 369 | The field object will also stringify to its name. | ||||||||||||||||||||||||||||||||||||||||||
| 370 | |||||||||||||||||||||||||||||||||||||||||||
| 371 | my $setter_name = "set_$field"; | ||||||||||||||||||||||||||||||||||||||||||
| 372 | |||||||||||||||||||||||||||||||||||||||||||
| 373 | Errors ("No field name") if you try to set a blank name. | ||||||||||||||||||||||||||||||||||||||||||
| 374 | |||||||||||||||||||||||||||||||||||||||||||
| 375 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 376 | |||||||||||||||||||||||||||||||||||||||||||
| 377 | 1623 | ▶ | has name => (is => 'rw', isa => sub { throw("No field name") unless $_[0] }); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 378 | |||||||||||||||||||||||||||||||||||||||||||
| 379 | 24899 | ▶ | around name => sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||
| 380 | 24899 | my $orig = shift; | |||||||||||||||||||||||||||||||||||||||||
| 381 | 24899 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 382 | |||||||||||||||||||||||||||||||||||||||||||
| 383 | 24899 | ▶ | if (my ($arg) = @_) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 384 | 110 | ▶ | if (my $schema = $self->table) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 385 | 110 | ▶ | return $self->error(qq[Can't use field name "$arg": field exists]) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 386 | if $schema->get_field($arg); | ||||||||||||||||||||||||||||||||||||||||||
| 387 | } | ||||||||||||||||||||||||||||||||||||||||||
| 388 | } | ||||||||||||||||||||||||||||||||||||||||||
| 389 | |||||||||||||||||||||||||||||||||||||||||||
| 390 | 24794 | return ex2err($orig, $self, @_); | |||||||||||||||||||||||||||||||||||||||||
| 391 | 76 | }; | |||||||||||||||||||||||||||||||||||||||||
| 392 | |||||||||||||||||||||||||||||||||||||||||||
| 393 | 1 | ▶ | sub full_name { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
full_name: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 394 | |||||||||||||||||||||||||||||||||||||||||||
| 395 | =head2 full_name | ||||||||||||||||||||||||||||||||||||||||||
| 396 | |||||||||||||||||||||||||||||||||||||||||||
| 397 | Read only method to return the fields name with its table name pre-pended. | ||||||||||||||||||||||||||||||||||||||||||
| 398 | e.g. "person.foo". | ||||||||||||||||||||||||||||||||||||||||||
| 399 | |||||||||||||||||||||||||||||||||||||||||||
| 400 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 401 | |||||||||||||||||||||||||||||||||||||||||||
| 402 | 1 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 403 | 1 | return $self->table . "." . $self->name; | |||||||||||||||||||||||||||||||||||||||||
| 404 | } | ||||||||||||||||||||||||||||||||||||||||||
| 405 | |||||||||||||||||||||||||||||||||||||||||||
| 406 | =head2 order | ||||||||||||||||||||||||||||||||||||||||||
| 407 | |||||||||||||||||||||||||||||||||||||||||||
| 408 | Get or set the field's order. | ||||||||||||||||||||||||||||||||||||||||||
| 409 | |||||||||||||||||||||||||||||||||||||||||||
| 410 | my $order = $field->order(3); | ||||||||||||||||||||||||||||||||||||||||||
| 411 | |||||||||||||||||||||||||||||||||||||||||||
| 412 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 413 | |||||||||||||||||||||||||||||||||||||||||||
| 414 | 76 | has order => (is => 'rw', default => quote_sub(q{ 0 })); | |||||||||||||||||||||||||||||||||||||||||
| 415 | |||||||||||||||||||||||||||||||||||||||||||
| 416 | 18379 | ▶ | around order => sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||
| 417 | 18379 | my ($orig, $self, $arg) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 418 | |||||||||||||||||||||||||||||||||||||||||||
| 419 | 18379 | ▶ | if (defined $arg && $arg =~ /^\d+$/) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $arg and $arg =~ /^\d+$/
MC/DC50%1/2
defined $arg and $arg =~ /^\d+$/
defined $arg
$arg =~ /^\d+$/
Truth table66%2/3
A and B
A= defined $argB= $arg =~ /^\d+$/
| |||||||||||||||||||||||||||||||||||||||||||
| 420 | 1348 | return $self->$orig($arg); | |||||||||||||||||||||||||||||||||||||||||
| 421 | } | ||||||||||||||||||||||||||||||||||||||||||
| 422 | |||||||||||||||||||||||||||||||||||||||||||
| 423 | 17031 | return $self->$orig; | |||||||||||||||||||||||||||||||||||||||||
| 424 | 76 | }; | |||||||||||||||||||||||||||||||||||||||||
| 425 | |||||||||||||||||||||||||||||||||||||||||||
| 426 | 1 | ▶ | sub schema { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
schema: called CC=3 SCAR=12.5
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 427 | |||||||||||||||||||||||||||||||||||||||||||
| 428 | =head2 schema | ||||||||||||||||||||||||||||||||||||||||||
| 429 | |||||||||||||||||||||||||||||||||||||||||||
| 430 | Shortcut to get the fields schema ($field->table->schema) or undef if it | ||||||||||||||||||||||||||||||||||||||||||
| 431 | doesn't have one. | ||||||||||||||||||||||||||||||||||||||||||
| 432 | |||||||||||||||||||||||||||||||||||||||||||
| 433 | my $schema = $field->schema; | ||||||||||||||||||||||||||||||||||||||||||
| 434 | |||||||||||||||||||||||||||||||||||||||||||
| 435 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 436 | |||||||||||||||||||||||||||||||||||||||||||
| 437 | 1 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 438 | 1 | ▶ | if (my $table = $self->table) { return $table->schema || undef; } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
$table->schema || undef
MC/DC0%0/1
$table->schema || undef
$table->schema
Truth table50%1/2
A
A= $table->schema
| |||||||||||||||||||||||||||||||||||||||||||
| 439 | 0 | return undef; | |||||||||||||||||||||||||||||||||||||||||
| 440 | } | ||||||||||||||||||||||||||||||||||||||||||
| 441 | |||||||||||||||||||||||||||||||||||||||||||
| 442 | =head2 size | ||||||||||||||||||||||||||||||||||||||||||
| 443 | |||||||||||||||||||||||||||||||||||||||||||
| 444 | Get or set the field's size. Accepts a string, array or arrayref of | ||||||||||||||||||||||||||||||||||||||||||
| 445 | numbers and returns a string. | ||||||||||||||||||||||||||||||||||||||||||
| 446 | |||||||||||||||||||||||||||||||||||||||||||
| 447 | $field->size( 30 ); | ||||||||||||||||||||||||||||||||||||||||||
| 448 | $field->size( [ 255 ] ); | ||||||||||||||||||||||||||||||||||||||||||
| 449 | $size = $field->size( 10, 2 ); | ||||||||||||||||||||||||||||||||||||||||||
| 450 | print $size; # prints "10,2" | ||||||||||||||||||||||||||||||||||||||||||
| 451 | |||||||||||||||||||||||||||||||||||||||||||
| 452 | $size = $field->size( '10, 2' ); | ||||||||||||||||||||||||||||||||||||||||||
| 453 | print $size; # prints "10,2" | ||||||||||||||||||||||||||||||||||||||||||
| 454 | |||||||||||||||||||||||||||||||||||||||||||
| 455 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 456 | |||||||||||||||||||||||||||||||||||||||||||
| 457 | has size => ( | ||||||||||||||||||||||||||||||||||||||||||
| 458 | is => 'rw', | ||||||||||||||||||||||||||||||||||||||||||
| 459 | default => quote_sub(q{ [0] }), | ||||||||||||||||||||||||||||||||||||||||||
| 460 | 1801 | ▶ | coerce => sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.3
| |||||||||||||||||||||||||||||||||||||||||||
| 461 | 1801 | ▶ | my @sizes = grep { defined && m/^\d+(?:\.\d+)?$/ } @{ parse_list_arg($_[0]) }; | ||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
defined $_ && /^\d+(?:\.\d+)?$/
MC/DC0%0/2
defined $_ && /^\d+(?:\.\d+)?$/
defined $_
/^\d+(?:\.\d+)?$/
Truth table33%1/3
A && B
A= defined $_B= /^\d+(?:\.\d+)?$/
| |||||||||||||||||||||||||||||||||||||||||||
| 462 | 1801 | ▶ | @sizes ? \@sizes : [0]; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 463 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 464 | 76 | ); | |||||||||||||||||||||||||||||||||||||||||
| 465 | |||||||||||||||||||||||||||||||||||||||||||
| 466 | 3230 | ▶ | around size => sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=9 SCAR=22.9
| |||||||||||||||||||||||||||||||||||||||||||
| 467 | 3230 | my $orig = shift; | |||||||||||||||||||||||||||||||||||||||||
| 468 | 3230 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 469 | 3230 | my $numbers = parse_list_arg(@_); | |||||||||||||||||||||||||||||||||||||||||
| 470 | |||||||||||||||||||||||||||||||||||||||||||
| 471 | 3230 | ▶ | if (@$numbers) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 472 | 185 | my @new; | |||||||||||||||||||||||||||||||||||||||||
| 473 | 185 | for my $num (@$numbers) { | |||||||||||||||||||||||||||||||||||||||||
| 474 | 192 | ▶ | if (defined $num && $num =~ m/^\d+(?:\.\d+)?$/) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $num and $num =~ /^\d+(?:\.\d+)?$/
MC/DC0%0/2
defined $num and $num =~ /^\d+(?:\.\d+)?$/
defined $num
$num =~ /^\d+(?:\.\d+)?$/
Truth table33%1/3
A and B
A= defined $numB= $num =~ /^\d+(?:\.\d+)?$/
| |||||||||||||||||||||||||||||||||||||||||||
| 475 | 192 | push @new, $num; | |||||||||||||||||||||||||||||||||||||||||
| 476 | } | ||||||||||||||||||||||||||||||||||||||||||
| 477 | } | ||||||||||||||||||||||||||||||||||||||||||
| 478 | 185 | ▶ | $self->$orig(\@new) if @new; # only set if all OK | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 479 | } | ||||||||||||||||||||||||||||||||||||||||||
| 480 | |||||||||||||||||||||||||||||||||||||||||||
| 481 | return wantarray | ||||||||||||||||||||||||||||||||||||||||||
| 482 | 1120 | ▶ | ? @{ $self->$orig || [0] } | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$self->$orig || [0]
MC/DC0%0/1
$self->$orig || [0]
$self->$orig
Truth table50%1/2
A
A= $self->$orig
| |||||||||||||||||||||||||||||||||||||||||||
| 483 | 3230 | ▶ | : join(',', @{ $self->$orig || [0] }); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
$self->$orig || [0]
MC/DC0%0/1
$self->$orig || [0]
$self->$orig
Truth table50%1/2
A
A= $self->$orig
| |||||||||||||||||||||||||||||||||||||||||||
| 484 | 76 | }; | |||||||||||||||||||||||||||||||||||||||||
| 485 | |||||||||||||||||||||||||||||||||||||||||||
| 486 | =head2 table | ||||||||||||||||||||||||||||||||||||||||||
| 487 | |||||||||||||||||||||||||||||||||||||||||||
| 488 | Get or set the field's table object. As the table object stringifies this can | ||||||||||||||||||||||||||||||||||||||||||
| 489 | also be used to get the table name. | ||||||||||||||||||||||||||||||||||||||||||
| 490 | |||||||||||||||||||||||||||||||||||||||||||
| 491 | my $table = $field->table; | ||||||||||||||||||||||||||||||||||||||||||
| 492 | print "Table name: $table"; | ||||||||||||||||||||||||||||||||||||||||||
| 493 | |||||||||||||||||||||||||||||||||||||||||||
| 494 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 495 | |||||||||||||||||||||||||||||||||||||||||||
| 496 | 76 | has table => (is => 'rw', isa => schema_obj('Table'), weak_ref => 1); | |||||||||||||||||||||||||||||||||||||||||
| 497 | |||||||||||||||||||||||||||||||||||||||||||
| 498 | 76 | around table => \&ex2err; | |||||||||||||||||||||||||||||||||||||||||
| 499 | |||||||||||||||||||||||||||||||||||||||||||
| 500 | =head2 parsed_field | ||||||||||||||||||||||||||||||||||||||||||
| 501 | |||||||||||||||||||||||||||||||||||||||||||
| 502 | Returns the field exactly as the parser found it | ||||||||||||||||||||||||||||||||||||||||||
| 503 | |||||||||||||||||||||||||||||||||||||||||||
| 504 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 505 | |||||||||||||||||||||||||||||||||||||||||||
| 506 | 76 | has parsed_field => (is => 'rw'); | |||||||||||||||||||||||||||||||||||||||||
| 507 | |||||||||||||||||||||||||||||||||||||||||||
| 508 | 521 | ▶ | around parsed_field => sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.0
| |||||||||||||||||||||||||||||||||||||||||||
| 509 | 521 | my $orig = shift; | |||||||||||||||||||||||||||||||||||||||||
| 510 | 521 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 511 | |||||||||||||||||||||||||||||||||||||||||||
| 512 | 521 | ▶ | return $self->$orig(@_) || $self; | ||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$self->$orig(@_) || $self
MC/DC0%0/2
$self->$orig(@_) || $self
$self->$orig(@_)
$self
Truth table66%2/3
A || B
A= $self->$orig(@_)B= $self
| |||||||||||||||||||||||||||||||||||||||||||
| 513 | 76 | }; | |||||||||||||||||||||||||||||||||||||||||
| 514 | |||||||||||||||||||||||||||||||||||||||||||
| 515 | =head2 equals | ||||||||||||||||||||||||||||||||||||||||||
| 516 | |||||||||||||||||||||||||||||||||||||||||||
| 517 | Determines if this field is the same as another | ||||||||||||||||||||||||||||||||||||||||||
| 518 | |||||||||||||||||||||||||||||||||||||||||||
| 519 | my $isIdentical = $field1->equals( $field2 ); | ||||||||||||||||||||||||||||||||||||||||||
| 520 | |||||||||||||||||||||||||||||||||||||||||||
| 521 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 522 | |||||||||||||||||||||||||||||||||||||||||||
| 523 | 428 | ▶ | around equals => sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=24 SCAR=32.3
| |||||||||||||||||||||||||||||||||||||||||||
| 524 | 428 | my $orig = shift; | |||||||||||||||||||||||||||||||||||||||||
| 525 | 428 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 526 | 428 | my $other = shift; | |||||||||||||||||||||||||||||||||||||||||
| 527 | 428 | my $case_insensitive = shift; | |||||||||||||||||||||||||||||||||||||||||
| 528 | |||||||||||||||||||||||||||||||||||||||||||
| 529 | 428 | ▶ | return 0 unless $self->$orig($other); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 530 | 428 | ▶ | return 0 | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 531 | unless $case_insensitive | ||||||||||||||||||||||||||||||||||||||||||
| 532 | ? uc($self->name) eq uc($other->name) | ||||||||||||||||||||||||||||||||||||||||||
| 533 | : $self->name eq $other->name; | ||||||||||||||||||||||||||||||||||||||||||
| 534 | |||||||||||||||||||||||||||||||||||||||||||
| 535 | # Comparing types: use sql_data_type if both are not 0. Else use string data_type | ||||||||||||||||||||||||||||||||||||||||||
| 536 | 428 | ▶ | if ($self->sql_data_type && $other->sql_data_type) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$self->sql_data_type and $other->sql_data_type
MC/DC50%1/2
$self->sql_data_type and $other->sql_data_type
$self->sql_data_type
$other->sql_data_type
Truth table66%2/3
A and B
A= $self->sql_data_typeB= $other->sql_data_type
| |||||||||||||||||||||||||||||||||||||||||||
| 537 | 358 | ▶ | return 0 unless $self->sql_data_type == $other->sql_data_type; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 538 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 539 | 70 | ▶ | return 0 unless lc($self->data_type) eq lc($other->data_type); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 540 | } | ||||||||||||||||||||||||||||||||||||||||||
| 541 | |||||||||||||||||||||||||||||||||||||||||||
| 542 | 374 | ▶ | return 0 unless $self->size eq $other->size; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 543 | |||||||||||||||||||||||||||||||||||||||||||
| 544 | { | ||||||||||||||||||||||||||||||||||||||||||
| 545 | 349 | my $lhs = $self->default_value; | |||||||||||||||||||||||||||||||||||||||||
| 546 | 349 | ▶ | $lhs = \'NULL' unless defined $lhs; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 547 | 349 | my $lhs_is_ref = !!ref $lhs; | |||||||||||||||||||||||||||||||||||||||||
| 548 | |||||||||||||||||||||||||||||||||||||||||||
| 549 | 349 | my $rhs = $other->default_value; | |||||||||||||||||||||||||||||||||||||||||
| 550 | 349 | ▶ | $rhs = \'NULL' unless defined $rhs; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 551 | 349 | my $rhs_is_ref = !!ref $rhs; | |||||||||||||||||||||||||||||||||||||||||
| 552 | |||||||||||||||||||||||||||||||||||||||||||
| 553 | # If only one is a ref, fail. -- rjbs, 2008-12-02 | ||||||||||||||||||||||||||||||||||||||||||
| 554 | 349 | ▶ | return 0 if $lhs_is_ref xor $rhs_is_ref; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition75%3/4
$lhs_is_ref xor $rhs_is_ref
MC/DC100%2/2
$lhs_is_ref xor $rhs_is_ref
$lhs_is_ref
$rhs_is_ref
Truth table75%3/4
A xor B
A= $lhs_is_refB= $rhs_is_ref
| |||||||||||||||||||||||||||||||||||||||||||
| 555 | |||||||||||||||||||||||||||||||||||||||||||
| 556 | 310 | ▶ | my $effective_lhs = $lhs_is_ref ? $$lhs : $lhs; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 557 | 310 | ▶ | my $effective_rhs = $rhs_is_ref ? $$rhs : $rhs; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 558 | |||||||||||||||||||||||||||||||||||||||||||
| 559 | 310 | ▶ | if ( $self->_is_numeric_data_type | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
$self->_is_numeric_data_type and &Scalar::Util::looks_like_number($effective_lhs) and &Scalar::Util::looks_like_number($effective_rhs)
$self->_is_numeric_data_type and &Scalar::Util::looks_like_number($effective_lhs)
MC/DC66%2/3
$self->_is_numeric_data_type and &Scalar::Util::looks_like_number($effective_lhs) and &Scalar::Util::looks_like_number($effective_rhs)
$self->_is_numeric_data_type
&Scalar::Util::looks_like_number($effective_lhs)
&Scalar::Util::looks_like_number($effective_rhs)
Truth table75%3/4
A and B and C
A= $self->_is_numeric_data_typeB= &Scalar::Util::looks_like_number($effective_lhs)C= &Scalar::Util::looks_like_number($effective_rhs)
| |||||||||||||||||||||||||||||||||||||||||||
| 560 | && Scalar::Util::looks_like_number($effective_lhs) | ||||||||||||||||||||||||||||||||||||||||||
| 561 | && Scalar::Util::looks_like_number($effective_rhs)) { | ||||||||||||||||||||||||||||||||||||||||||
| 562 | 16 | ▶ | return 0 if ($effective_lhs + 0) != ($effective_rhs + 0); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 563 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 564 | 294 | ▶ | return 0 if $effective_lhs ne $effective_rhs; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 565 | } | ||||||||||||||||||||||||||||||||||||||||||
| 566 | } | ||||||||||||||||||||||||||||||||||||||||||
| 567 | |||||||||||||||||||||||||||||||||||||||||||
| 568 | 310 | ▶ | return 0 unless $self->is_nullable eq $other->is_nullable; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 569 | |||||||||||||||||||||||||||||||||||||||||||
| 570 | # return 0 unless $self->is_unique eq $other->is_unique; | ||||||||||||||||||||||||||||||||||||||||||
| 571 | 253 | ▶ | return 0 unless $self->is_primary_key eq $other->is_primary_key; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 572 | |||||||||||||||||||||||||||||||||||||||||||
| 573 | # return 0 unless $self->is_foreign_key eq $other->is_foreign_key; | ||||||||||||||||||||||||||||||||||||||||||
| 574 | 253 | ▶ | return 0 unless $self->is_auto_increment eq $other->is_auto_increment; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 575 | |||||||||||||||||||||||||||||||||||||||||||
| 576 | # return 0 unless $self->comments eq $other->comments; | ||||||||||||||||||||||||||||||||||||||||||
| 577 | 213 | ▶ | return 0 | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 578 | unless $self->_compare_objects(scalar $self->extra, scalar $other->extra); | ||||||||||||||||||||||||||||||||||||||||||
| 579 | 213 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 580 | 76 | }; | |||||||||||||||||||||||||||||||||||||||||
| 581 | |||||||||||||||||||||||||||||||||||||||||||
| 582 | # Must come after all 'has' declarations | ||||||||||||||||||||||||||||||||||||||||||
| 583 | 76 | around new => \&ex2err; | |||||||||||||||||||||||||||||||||||||||||
| 584 | |||||||||||||||||||||||||||||||||||||||||||
| 585 | 310 | ▶ | sub _is_numeric_data_type { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_is_numeric_data_type: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 586 | 310 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 587 | 310 | return $self->_numeric_sql_data_types->{ $self->sql_data_type }; | |||||||||||||||||||||||||||||||||||||||||
| 588 | } | ||||||||||||||||||||||||||||||||||||||||||
| 589 | |||||||||||||||||||||||||||||||||||||||||||
| 590 | 76 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 591 | |||||||||||||||||||||||||||||||||||||||||||
| 592 | =pod | ||||||||||||||||||||||||||||||||||||||||||
| 593 | |||||||||||||||||||||||||||||||||||||||||||
| 594 | =head1 AUTHOR | ||||||||||||||||||||||||||||||||||||||||||
| 595 | |||||||||||||||||||||||||||||||||||||||||||
| 596 | Ken Youens-Clark E<lt>kclark@cpan.orgE<gt>. | ||||||||||||||||||||||||||||||||||||||||||
| 597 | |||||||||||||||||||||||||||||||||||||||||||
| 598 | =cut | ||||||||||||||||||||||||||||||||||||||||||