← Index
NYTProf Performance Profile   « block view • line view • sub view »
For xt/tapper-mcp-scheduler-with-db-longrun.t
  Run on Tue May 22 17:18:39 2012
Reported on Tue May 22 17:23:18 2012

Filename/2home/ss5/perl5/perlbrew/perls/perl-5.12.3/lib/site_perl/5.12.3/SQL/Translator/Schema/Field.pm
StatementsExecuted 29049 statements in 32.7ms
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
2217644.65ms7.76msSQL::Translator::Schema::Field::::nameSQL::Translator::Schema::Field::name
1297743.81ms5.48msSQL::Translator::Schema::Field::::__ANON__[:58]SQL::Translator::Schema::Field::__ANON__[:58]
480223.25ms7.11msSQL::Translator::Schema::Field::::sizeSQL::Translator::Schema::Field::size
575333.01ms9.03msSQL::Translator::Schema::Field::::is_primary_keySQL::Translator::Schema::Field::is_primary_key
1161532.71ms4.01msSQL::Translator::Schema::Field::::tableSQL::Translator::Schema::Field::table
240112.13ms4.98msSQL::Translator::Schema::Field::::is_foreign_keySQL::Translator::Schema::Field::is_foreign_key
480221.77ms6.84msSQL::Translator::Schema::Field::::is_nullableSQL::Translator::Schema::Field::is_nullable
535331.36ms1.37msSQL::Translator::Schema::Field::::data_typeSQL::Translator::Schema::Field::data_type
480211.36ms1.62msSQL::Translator::Schema::Field::::orderSQL::Translator::Schema::Field::order
480221.07ms1.07msSQL::Translator::Schema::Field::::is_auto_incrementSQL::Translator::Schema::Field::is_auto_increment
48021656µs656µsSQL::Translator::Schema::Field::::CORE:matchSQL::Translator::Schema::Field::CORE:match (opcode)
24011589µs589µsSQL::Translator::Schema::Field::::commentsSQL::Translator::Schema::Field::comments
14753462µs640µsSQL::Translator::Schema::Field::::__ANON__[:57]SQL::Translator::Schema::Field::__ANON__[:57]
29522445µs445µsSQL::Translator::Schema::Field::::default_valueSQL::Translator::Schema::Field::default_value
11114µs18µsSQL::Translator::Schema::Field::::BEGIN@43SQL::Translator::Schema::Field::BEGIN@43
11112µs53µsSQL::Translator::Schema::Field::::BEGIN@57SQL::Translator::Schema::Field::BEGIN@57
11111µs680µsSQL::Translator::Schema::Field::::BEGIN@62SQL::Translator::Schema::Field::BEGIN@62
1119µs73µsSQL::Translator::Schema::Field::::BEGIN@44SQL::Translator::Schema::Field::BEGIN@44
1118µs77µsSQL::Translator::Schema::Field::::BEGIN@47SQL::Translator::Schema::Field::BEGIN@47
1117µs49µsSQL::Translator::Schema::Field::::BEGIN@49SQL::Translator::Schema::Field::BEGIN@49
1117µs27µsSQL::Translator::Schema::Field::::BEGIN@45SQL::Translator::Schema::Field::BEGIN@45
0000s0sSQL::Translator::Schema::Field::::DESTROYSQL::Translator::Schema::Field::DESTROY
0000s0sSQL::Translator::Schema::Field::::equalsSQL::Translator::Schema::Field::equals
0000s0sSQL::Translator::Schema::Field::::foreign_key_referenceSQL::Translator::Schema::Field::foreign_key_reference
0000s0sSQL::Translator::Schema::Field::::full_nameSQL::Translator::Schema::Field::full_name
0000s0sSQL::Translator::Schema::Field::::is_uniqueSQL::Translator::Schema::Field::is_unique
0000s0sSQL::Translator::Schema::Field::::is_validSQL::Translator::Schema::Field::is_valid
0000s0sSQL::Translator::Schema::Field::::parsed_fieldSQL::Translator::Schema::Field::parsed_field
0000s0sSQL::Translator::Schema::Field::::schemaSQL::Translator::Schema::Field::schema
0000s0sSQL::Translator::Schema::Field::::sql_data_typeSQL::Translator::Schema::Field::sql_data_type
Call graph for these subroutines as a Graphviz dot language file.
Line State
ments
Time
on line
Calls Time
in subs
Code
1package SQL::Translator::Schema::Field;
2
3# ----------------------------------------------------------------------
4# Copyright (C) 2002-2009 SQLFairy Authors
5#
6# This program is free software; you can redistribute it and/or
7# modify it under the terms of the GNU General Public License as
8# published by the Free Software Foundation; version 2.
9#
10# This program is distributed in the hope that it will be useful, but
11# WITHOUT ANY WARRANTY; without even the implied warranty of
12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13# General Public License for more details.
14#
15# You should have received a copy of the GNU General Public License
16# along with this program; if not, write to the Free Software
17# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
18# 02111-1307 USA
19# -------------------------------------------------------------------
20
21=pod
22
23=head1 NAME
24
25SQL::Translator::Schema::Field - SQL::Translator field object
26
27=head1 SYNOPSIS
28
29 use SQL::Translator::Schema::Field;
30 my $field = SQL::Translator::Schema::Field->new(
31 name => 'foo',
32 table => $table,
33 );
34
35=head1 DESCRIPTION
36
37C<SQL::Translator::Schema::Field> is the field object.
38
39=head1 METHODS
40
41=cut
42
43322µs221µs
# spent 18µs (14+4) within SQL::Translator::Schema::Field::BEGIN@43 which was called: # once (14µs+4µs) by SQL::Translator::Schema::Table::BEGIN@44 at line 43
use strict;
# spent 18µs making 1 call to SQL::Translator::Schema::Field::BEGIN@43 # spent 4µs making 1 call to strict::import
44321µs2137µs
# spent 73µs (9+64) within SQL::Translator::Schema::Field::BEGIN@44 which was called: # once (9µs+64µs) by SQL::Translator::Schema::Table::BEGIN@44 at line 44
use SQL::Translator::Schema::Constants;
# spent 73µs making 1 call to SQL::Translator::Schema::Field::BEGIN@44 # spent 64µs making 1 call to Exporter::import
45323µs248µs
# spent 27µs (7+20) within SQL::Translator::Schema::Field::BEGIN@45 which was called: # once (7µs+20µs) by SQL::Translator::Schema::Table::BEGIN@44 at line 45
use SQL::Translator::Utils 'parse_list_arg';
# spent 27µs making 1 call to SQL::Translator::Schema::Field::BEGIN@45 # spent 20µs making 1 call to Exporter::import
46
47324µs2145µs
# spent 77µs (8+69) within SQL::Translator::Schema::Field::BEGIN@47 which was called: # once (8µs+69µs) by SQL::Translator::Schema::Table::BEGIN@44 at line 47
use base 'SQL::Translator::Schema::Object';
# spent 77µs making 1 call to SQL::Translator::Schema::Field::BEGIN@47 # spent 69µs making 1 call to base::import
48
49372µs290µs
# spent 49µs (7+41) within SQL::Translator::Schema::Field::BEGIN@49 which was called: # once (7µs+41µs) by SQL::Translator::Schema::Table::BEGIN@44 at line 49
use vars qw($VERSION $TABLE_COUNT $VIEW_COUNT);
# spent 49µs making 1 call to SQL::Translator::Schema::Field::BEGIN@49 # spent 41µs making 1 call to vars::import
50
511600ns$VERSION = '1.59';
52
53# Stringify to our name, being careful not to pass any args through so we don't
54# accidentally set it to undef. We also have to tweak bool so the object is
55# still true when it doesn't have a name (which shouldn't happen!).
56use overload
57147408µs147178µs
# spent 53µs (12+42) within SQL::Translator::Schema::Field::BEGIN@57 which was called: # once (12µs+42µs) by SQL::Translator::Schema::Table::BEGIN@44 at line 60 # spent 640µs (462+178) within SQL::Translator::Schema::Field::__ANON__[/2home/ss5/perl5/perlbrew/perls/perl-5.12.3/lib/site_perl/5.12.3/SQL/Translator/Schema/Field.pm:57] which was called 147 times, avg 4µs/call: # 54 times (168µs+65µs) by SQL::Translator::Schema::Field::is_primary_key at line 385, avg 4µs/call # 39 times (142µs+47µs) by SQL::Translator::Schema::Table::get_field at line 514 of SQL/Translator/Schema/Table.pm, avg 5µs/call # 39 times (108µs+46µs) by SQL::Translator::Schema::Table::get_field at line 516 of SQL/Translator/Schema/Table.pm, avg 4µs/call # 12 times (35µs+16µs) by SQL::Translator::Producer::SQLite::create_table at line 216 of SQL/Translator/Producer/SQLite.pm, avg 4µs/call # 3 times (10µs+4µs) by SQL::Translator::Producer::SQLite::create_constraint at line 365 of SQL/Translator/Producer/SQLite.pm, avg 5µs/call
'""' => sub { shift->name },
# spent 178µs making 147 calls to SQL::Translator::Schema::Field::name, avg 1µs/call
5812973.27ms12971.67ms
# spent 5.48ms (3.81+1.67) within SQL::Translator::Schema::Field::__ANON__[/2home/ss5/perl5/perlbrew/perls/perl-5.12.3/lib/site_perl/5.12.3/SQL/Translator/Schema/Field.pm:58] which was called 1297 times, avg 4µs/call: # 460 times (1.41ms+621µs) by SQL::Translator::Schema::Constraint::fields at line 254 of SQL/Translator/Schema/Constraint.pm, avg 4µs/call # 240 times (733µs+324µs) by Class::Base::new at line 59 of Class/Base.pm, avg 4µs/call # 240 times (682µs+286µs) by SQL::Translator::Parser::DBIx::Class::parse at line 120 of SQL/Translator/Parser/DBIx/Class.pm, avg 4µs/call # 240 times (658µs+298µs) by SQL::Translator::Schema::Table::add_field at line 333 of SQL/Translator/Schema/Table.pm, avg 4µs/call # 39 times (117µs+50µs) by SQL::Translator::Schema::Table::primary_key at line 815 of SQL/Translator/Schema/Table.pm, avg 4µs/call # 39 times (106µs+46µs) by SQL::Translator::Schema::Table::get_field at line 505 of SQL/Translator/Schema/Table.pm, avg 4µs/call # 39 times (104µs+45µs) by SQL::Translator::Schema::Table::add_constraint at line 146 of SQL/Translator/Schema/Table.pm, avg 4µs/call
'bool' => sub { $_[0]->name || $_[0] },
# spent 1.67ms making 1297 calls to SQL::Translator::Schema::Field::name, avg 1µs/call
59142µs fallback => 1,
# spent 42µs making 1 call to overload::import
60329µs153µs;
# spent 53µs making 1 call to SQL::Translator::Schema::Field::BEGIN@57
61
6231.40ms21.35ms
# spent 680µs (11+669) within SQL::Translator::Schema::Field::BEGIN@62 which was called: # once (11µs+669µs) by SQL::Translator::Schema::Table::BEGIN@44 at line 62
use DBI qw(:sql_types);
# spent 680µs making 1 call to SQL::Translator::Schema::Field::BEGIN@62 # spent 669µs making 1 call to Exporter::import
63
64# Mapping from string to sql contstant
651100µs1912µsour %type_mapping = (
# spent 4µs making 2 calls to DBI::SQL_INTEGER, avg 2µs/call # spent 1µs making 2 calls to DBI::SQL_BLOB, avg 500ns/call # spent 1µs making 2 calls to DBI::SQL_DECIMAL, avg 500ns/call # spent 600ns making 1 call to DBI::SQL_LONGVARCHAR # spent 600ns making 1 call to DBI::SQL_NUMERIC # spent 600ns making 1 call to DBI::SQL_VARBINARY # spent 500ns making 1 call to DBI::SQL_BINARY # spent 500ns making 1 call to DBI::SQL_DATETIME # spent 500ns making 1 call to DBI::SQL_SMALLINT # spent 500ns making 1 call to DBI::SQL_TIME # spent 500ns making 1 call to DBI::SQL_VARCHAR # spent 400ns making 1 call to DBI::SQL_BIT # spent 400ns making 1 call to DBI::SQL_CHAR # spent 400ns making 1 call to DBI::SQL_DATE # spent 400ns making 1 call to DBI::SQL_DOUBLE # spent 400ns making 1 call to DBI::SQL_TIMESTAMP
66 integer => SQL_INTEGER,
67 int => SQL_INTEGER,
68
69 smallint => SQL_SMALLINT,
70 bigint => 9999, # DBI doesn't export a constatn for this. Le suck
71
72 double => SQL_DOUBLE,
73
74 decimal => SQL_DECIMAL,
75 numeric => SQL_NUMERIC,
76 dec => SQL_DECIMAL,
77
78 bit => SQL_BIT,
79
80 date => SQL_DATE,
81 datetime => SQL_DATETIME,
82 timestamp => SQL_TIMESTAMP,
83 time => SQL_TIME,
84
85 char => SQL_CHAR,
86 varchar => SQL_VARCHAR,
87 binary => SQL_BINARY,
88 varbinary => SQL_VARBINARY,
89 tinyblob => SQL_BLOB,
90 blob => SQL_BLOB,
91 text => SQL_LONGVARCHAR
92
93);
94# ----------------------------------------------------------------------
95
9618µs160µs__PACKAGE__->_attributes( qw/
# spent 60µs making 1 call to SQL::Translator::Schema::Object::_attributes
97 table name data_type size is_primary_key is_nullable
98 is_auto_increment default_value comments is_foreign_key
99 is_unique order sql_data_type
100/);
101
102=pod
103
104=head2 new
105
106Object constructor.
107
108 my $field = SQL::Translator::Schema::Field->new(
109 name => 'foo',
110 table => $table,
111 );
112
113=cut
114
115# ----------------------------------------------------------------------
116
# spent 589µs within SQL::Translator::Schema::Field::comments which was called 240 times, avg 2µs/call: # 240 times (589µs+0s) by SQL::Translator::Producer::SQLite::create_field at line 264 of SQL/Translator/Producer/SQLite.pm, avg 2µs/call
sub comments {
117
118=pod
119
120=head2 comments
121
122Get or set the comments on a field. May be called several times to
123set and it will accumulate the comments. Called in an array context,
124returns each comment individually; called in a scalar context, returns
125all the comments joined on newlines.
126
127 $field->comments('foo');
128 $field->comments('bar');
129 print join( ', ', $field->comments ); # prints "foo, bar"
130
131=cut
132
133720343µs my $self = shift;
134
135 for my $arg ( @_ ) {
136 $arg = $arg->[0] if ref $arg;
137 push @{ $self->{'comments'} }, $arg if $arg;
138 }
139
140240497µs if ( @{ $self->{'comments'} || [] } ) {
141 return wantarray
142 ? @{ $self->{'comments'} || [] }
143 : join( "\n", @{ $self->{'comments'} || [] } );
144 }
145 else {
146 return wantarray ? () : '';
147 }
148}
149
150
151# ----------------------------------------------------------------------
152
# spent 1.37ms (1.36+14µs) within SQL::Translator::Schema::Field::data_type which was called 535 times, avg 3µs/call: # 240 times (896µs+14µs) by SQL::Translator::Schema::Object::init at line 104 of SQL/Translator/Schema/Object.pm, avg 4µs/call # 240 times (381µs+0s) by SQL::Translator::Producer::SQLite::create_field at line 272 of SQL/Translator/Producer/SQLite.pm, avg 2µs/call # 55 times (81µs+0s) by SQL::Translator::Producer::_apply_default_value at line 53 of SQL/Translator/Producer.pm, avg 1µs/call
sub data_type {
153
154=pod
155
156=head2 data_type
157
158Get or set the field's data type.
159
160 my $data_type = $field->data_type('integer');
161
162=cut
163
16416051.35ms my $self = shift;
165480495µs if (@_) {
166 $self->{'data_type'} = $_[0];
167814µs $self->{'sql_data_type'} = $type_mapping{lc $_[0]} || SQL_UNKNOWN_TYPE unless exists $self->{sql_data_type};
# spent 14µs making 8 calls to DBI::SQL_UNKNOWN_TYPE, avg 2µs/call
168 }
169 return $self->{'data_type'} || '';
170}
171
172sub sql_data_type {
173
174=head2 sql_data_type
175
176Constant from DBI package representing this data type. See L<DBI/DBI Constants>
177for more details.
178
179=cut
180
181 my $self = shift;
182 $self->{sql_data_type} = shift if @_;
183 return $self->{sql_data_type} || 0;
184
185}
186
187# ----------------------------------------------------------------------
188
# spent 445µs within SQL::Translator::Schema::Field::default_value which was called 295 times, avg 2µs/call: # 240 times (323µs+0s) by SQL::Translator::Producer::_apply_default_value at line 37 of SQL/Translator/Producer.pm, avg 1µs/call # 55 times (122µs+0s) by SQL::Translator::Schema::Object::init at line 104 of SQL/Translator/Schema/Object.pm, avg 2µs/call
sub default_value {
189
190=pod
191
192=head2 default_value
193
194Get or set the field's default value. Will return undef if not defined
195and could return the empty string (it's a valid default value), so don't
196assume an error like other methods.
197
198 my $default = $field->default_value('foo');
199
200=cut
201
202885734µs my $self = shift;
203 $self->{'default_value'} = shift if @_;
204 return $self->{'default_value'};
205}
206
207# ----------------------------------------------------------------------
208=pod
209
210=head2 extra
211
212Get or set the field's "extra" attibutes (e.g., "ZEROFILL" for MySQL).
213Accepts a hash(ref) of name/value pairs to store; returns a hash.
214
215 $field->extra( qualifier => 'ZEROFILL' );
216 my %extra = $field->extra;
217
218=cut
219
220
221# ----------------------------------------------------------------------
222sub foreign_key_reference {
223
224=pod
225
226=head2 foreign_key_reference
227
228Get or set the field's foreign key reference;
229
230 my $constraint = $field->foreign_key_reference( $constraint );
231
232=cut
233
234 my $self = shift;
235
236 if ( my $arg = shift ) {
237 my $class = 'SQL::Translator::Schema::Constraint';
238 if ( UNIVERSAL::isa( $arg, $class ) ) {
239 return $self->error(
240 'Foreign key reference for ', $self->name, 'already defined'
241 ) if $self->{'foreign_key_reference'};
242
243 $self->{'foreign_key_reference'} = $arg;
244 }
245 else {
246 return $self->error(
247 "Argument to foreign_key_reference is not an $class object"
248 );
249 }
250 }
251
252 return $self->{'foreign_key_reference'};
253}
254
255# ----------------------------------------------------------------------
256
# spent 1.07ms within SQL::Translator::Schema::Field::is_auto_increment which was called 480 times, avg 2µs/call: # 240 times (619µs+0s) by SQL::Translator::Schema::Object::init at line 104 of SQL/Translator/Schema/Object.pm, avg 3µs/call # 240 times (447µs+0s) by SQL::Translator::Producer::SQLite::create_field at line 314 of SQL/Translator/Producer/SQLite.pm, avg 2µs/call
sub is_auto_increment {
257
258=pod
259
260=head2 is_auto_increment
261
262Get or set the field's C<is_auto_increment> attribute.
263
264 my $is_auto = $field->is_auto_increment(1);
265
266=cut
267
26819201.43ms my ( $self, $arg ) = @_;
269
270 if ( defined $arg ) {
271 $self->{'is_auto_increment'} = $arg ? 1 : 0;
272 }
273
274 unless ( defined $self->{'is_auto_increment'} ) {
275 if ( my $table = $self->table ) {
276 if ( my $schema = $table->schema ) {
277 if (
278 $schema->database eq 'PostgreSQL' &&
279 $self->data_type eq 'serial'
280 ) {
281 $self->{'is_auto_increment'} = 1;
282 }
283 }
284 }
285 }
286
287 return $self->{'is_auto_increment'} || 0;
288}
289
290# ----------------------------------------------------------------------
291
# spent 4.98ms (2.13+2.85) within SQL::Translator::Schema::Field::is_foreign_key which was called 240 times, avg 21µs/call: # 240 times (2.13ms+2.85ms) by SQL::Translator::Schema::Object::init at line 104 of SQL/Translator/Schema/Object.pm, avg 21µs/call
sub is_foreign_key {
292
293=pod
294
295=head2 is_foreign_key
296
297Returns whether or not the field is a foreign key.
298
299 my $is_fk = $field->is_foreign_key;
300
301=cut
302
303720684µs my ( $self, $arg ) = @_;
304
305240487µs unless ( defined $self->{'is_foreign_key'} ) {
306240492µs4801.39ms if ( my $table = $self->table ) {
# spent 1.07ms making 240 calls to SQL::Translator::Schema::Table::__ANON__[SQL/Translator/Schema/Table.pm:59], avg 4µs/call # spent 321µs making 240 calls to SQL::Translator::Schema::Field::table, avg 1µs/call
3072401.45ms for my $c ( $table->get_constraints ) {
# spent 1.45ms making 240 calls to SQL::Translator::Schema::Table::get_constraints, avg 6µs/call
308 if ( $c->type eq FOREIGN_KEY ) {
309 my %fields = map { $_, 1 } $c->fields;
310 if ( $fields{ $self->name } ) {
311 $self->{'is_foreign_key'} = 1;
312 $self->foreign_key_reference( $c );
313 last;
314 }
315 }
316 }
317 }
318 }
319
320 return $self->{'is_foreign_key'} || 0;
321}
322
323# ----------------------------------------------------------------------
324
# spent 6.84ms (1.77+5.07) within SQL::Translator::Schema::Field::is_nullable which was called 480 times, avg 14µs/call: # 240 times (995µs+4.86ms) by SQL::Translator::Schema::Object::init at line 104 of SQL/Translator/Schema/Object.pm, avg 24µs/call # 240 times (776µs+204µs) by SQL::Translator::Producer::SQLite::create_field at line 318 of SQL/Translator/Producer/SQLite.pm, avg 4µs/call
sub is_nullable {
325
326=pod
327
328=head2 is_nullable
329
330Get or set whether the field can be null. If not defined, then
331returns "1" (assumes the field can be null). The argument is evaluated
332by Perl for True or False, so the following are eqivalent:
333
334 $is_nullable = $field->is_nullable(0);
335 $is_nullable = $field->is_nullable('');
336 $is_nullable = $field->is_nullable('0');
337
338While this is technically a field constraint, it's probably easier to
339represent this as an attribute of the field. In order keep things
340consistent, any other constraint on the field (unique, primary, and
341foreign keys; checks) are represented as table constraints.
342
343=cut
344
34519201.85ms my ( $self, $arg ) = @_;
346
347 if ( defined $arg ) {
348 $self->{'is_nullable'} = $arg ? 1 : 0;
349 }
350
3512965.07ms if (
# spent 5.07ms making 296 calls to SQL::Translator::Schema::Field::is_primary_key, avg 17µs/call
352 defined $self->{'is_nullable'} &&
353 $self->{'is_nullable'} == 1 &&
354 $self->is_primary_key
355 ) {
356 $self->{'is_nullable'} = 0;
357 }
358
359 return defined $self->{'is_nullable'} ? $self->{'is_nullable'} : 1;
360}
361
362# ----------------------------------------------------------------------
363
# spent 9.03ms (3.01+6.02) within SQL::Translator::Schema::Field::is_primary_key which was called 575 times, avg 16µs/call: # 296 times (1.64ms+3.43ms) by SQL::Translator::Schema::Field::is_nullable at line 351, avg 17µs/call # 240 times (1.27ms+2.59ms) by SQL::Translator::Producer::SQLite::create_field at line 300 of SQL/Translator/Producer/SQLite.pm, avg 16µs/call # 39 times (105µs+0s) by SQL::Translator::Schema::Table::add_constraint at line 146 of SQL/Translator/Schema/Table.pm, avg 3µs/call
sub is_primary_key {
364
365=pod
366
367=head2 is_primary_key
368
369Get or set the field's C<is_primary_key> attribute. Does not create
370a table constraint (should it?).
371
372 my $is_pk = $field->is_primary_key(1);
373
374=cut
375
37623001.68ms my ( $self, $arg ) = @_;
377
378 if ( defined $arg ) {
379 $self->{'is_primary_key'} = $arg ? 1 : 0;
380 }
381
382201417µs unless ( defined $self->{'is_primary_key'} ) {
383201338µs4021.18ms if ( my $table = $self->table ) {
# spent 914µs making 201 calls to SQL::Translator::Schema::Table::__ANON__[SQL/Translator/Schema/Table.pm:59], avg 5µs/call # spent 266µs making 201 calls to SQL::Translator::Schema::Field::table, avg 1µs/call
384254347µs2013.32ms if ( my $pk = $table->primary_key ) {
# spent 3.32ms making 201 calls to SQL::Translator::Schema::Table::primary_key, avg 17µs/call
385140µs1071.45ms my %fields = map { $_, 1 } $pk->fields;
# spent 1.22ms making 53 calls to SQL::Translator::Schema::Constraint::fields, avg 23µs/call # spent 233µs making 54 calls to SQL::Translator::Schema::Field::__ANON__[SQL/Translator/Schema/Field.pm:57], avg 4µs/call
3865366µs $self->{'is_primary_key'} = $fields{ $self->name } || 0;
# spent 66µs making 53 calls to SQL::Translator::Schema::Field::name, avg 1µs/call
387 }
388 else {
389 $self->{'is_primary_key'} = 0;
390 }
391 }
392 }
393
394 return $self->{'is_primary_key'} || 0;
395}
396
397# ----------------------------------------------------------------------
398sub is_unique {
399
400=pod
401
402=head2 is_unique
403
404Determine whether the field has a UNIQUE constraint or not.
405
406 my $is_unique = $field->is_unique;
407
408=cut
409
410 my $self = shift;
411
412 unless ( defined $self->{'is_unique'} ) {
413 if ( my $table = $self->table ) {
414 for my $c ( $table->get_constraints ) {
415 if ( $c->type eq UNIQUE ) {
416 my %fields = map { $_, 1 } $c->fields;
417 if ( $fields{ $self->name } ) {
418 $self->{'is_unique'} = 1;
419 last;
420 }
421 }
422 }
423 }
424 }
425
426 return $self->{'is_unique'} || 0;
427}
428
429# ----------------------------------------------------------------------
430sub is_valid {
431
432=pod
433
434=head2 is_valid
435
436Determine whether the field is valid or not.
437
438 my $ok = $field->is_valid;
439
440=cut
441
442 my $self = shift;
443 return $self->error('No name') unless $self->name;
444 return $self->error('No data type') unless $self->data_type;
445 return $self->error('No table object') unless $self->table;
446 return 1;
447}
448
449# ----------------------------------------------------------------------
450
# spent 7.76ms (4.65+3.11) within SQL::Translator::Schema::Field::name which was called 2217 times, avg 3µs/call: # 1297 times (1.67ms+0s) by SQL::Translator::Schema::Field::__ANON__[/2home/ss5/perl5/perlbrew/perls/perl-5.12.3/lib/site_perl/5.12.3/SQL/Translator/Schema/Field.pm:58] at line 58, avg 1µs/call # 240 times (1.99ms+3.11ms) by SQL::Translator::Schema::Object::init at line 104 of SQL/Translator/Schema/Object.pm, avg 21µs/call # 240 times (408µs+0s) by SQL::Translator::Producer::SQLite::create_field at line 262 of SQL/Translator/Producer/SQLite.pm, avg 2µs/call # 240 times (335µs+0s) by SQL::Translator::Schema::Table::add_field at line 339 of SQL/Translator/Schema/Table.pm, avg 1µs/call # 147 times (178µs+0s) by SQL::Translator::Schema::Field::__ANON__[/2home/ss5/perl5/perlbrew/perls/perl-5.12.3/lib/site_perl/5.12.3/SQL/Translator/Schema/Field.pm:57] at line 57, avg 1µs/call # 53 times (66µs+0s) by SQL::Translator::Schema::Field::is_primary_key at line 386, avg 1µs/call
sub name {
451
452=pod
453
454=head2 name
455
456Get or set the field's name.
457
458 my $name = $field->name('foo');
459
460The field object will also stringify to its name.
461
462 my $setter_name = "set_$field";
463
464Errors ("No field name") if you try to set a blank name.
465
466=cut
467
46866515.64ms my $self = shift;
469
470720764µs if ( @_ ) {
471 my $arg = shift || return $self->error( "No field name" );
4721256µs7203.11ms if ( my $table = $self->table ) {
# spent 1.80ms making 240 calls to SQL::Translator::Schema::Table::get_field, avg 8µs/call # spent 1.01ms making 240 calls to SQL::Translator::Schema::Table::__ANON__[SQL/Translator/Schema/Table.pm:59], avg 4µs/call # spent 292µs making 240 calls to SQL::Translator::Schema::Field::table, avg 1µs/call
473 return $self->error( qq[Can't use field name "$arg": field exists] )
474 if $table->get_field( $arg );
475 }
476
477 $self->{'name'} = $arg;
478 }
479
480 return $self->{'name'} || '';
481}
482
483sub full_name {
484
485=head2 full_name
486
487Read only method to return the fields name with its table name pre-pended.
488e.g. "person.foo".
489
490=cut
491
492 my $self = shift;
493 return $self->table.".".$self->name;
494}
495
496# ----------------------------------------------------------------------
497
# spent 1.62ms (1.36+263µs) within SQL::Translator::Schema::Field::order which was called 480 times, avg 3µs/call: # 240 times (919µs+263µs) by SQL::Translator::Schema::Table::add_field at line 337 of SQL/Translator/Schema/Table.pm, avg 5µs/call # 240 times (437µs+0s) by SQL::Translator::Schema::Table::get_fields at line 535 of SQL/Translator/Schema/Table.pm, avg 2µs/call
sub order {
498
499=pod
500
501=head2 order
502
503Get or set the field's order.
504
505 my $order = $field->order(3);
506
507=cut
508
50914402.00ms my ( $self, $arg ) = @_;
510
511240263µs if ( defined $arg && $arg =~ /^\d+$/ ) {
# spent 263µs making 240 calls to SQL::Translator::Schema::Field::CORE:match, avg 1µs/call
512 $self->{'order'} = $arg;
513 }
514
515 return $self->{'order'} || 0;
516}
517
518# ----------------------------------------------------------------------
519sub schema {
520
521=head2 schema
522
523Shortcut to get the fields schema ($field->table->schema) or undef if it
524doesn't have one.
525
526 my $schema = $field->schema;
527
528=cut
529
530 my $self = shift;
531 if ( my $table = $self->table ) { return $table->schema || undef; }
532 return undef;
533}
534
535# ----------------------------------------------------------------------
536
# spent 7.11ms (3.25+3.86) within SQL::Translator::Schema::Field::size which was called 480 times, avg 15µs/call: # 240 times (2.27ms+2.89ms) by SQL::Translator::Schema::Object::init at line 104 of SQL/Translator/Schema/Object.pm, avg 22µs/call # 240 times (983µs+971µs) by SQL::Translator::Producer::SQLite::create_field at line 271 of SQL/Translator/Producer/SQLite.pm, avg 8µs/call
sub size {
537
538=pod
539
540=head2 size
541
542Get or set the field's size. Accepts a string, array or arrayref of
543numbers and returns a string.
544
545 $field->size( 30 );
546 $field->size( [ 255 ] );
547 $size = $field->size( 10, 2 );
548 print $size; # prints "10,2"
549
550 $size = $field->size( '10, 2' );
551 print $size; # prints "10,2"
552
553=cut
554
55519202.12ms my $self = shift;
5564803.47ms my $numbers = parse_list_arg( @_ );
# spent 3.47ms making 480 calls to SQL::Translator::Utils::parse_list_arg, avg 7µs/call
557
558720547µs if ( @$numbers ) {
559 my @new;
560 for my $num ( @$numbers ) {
5612401.05ms240393µs if ( defined $num && $num =~ m/^\d+(?:\.\d+)?$/ ) {
# spent 393µs making 240 calls to SQL::Translator::Schema::Field::CORE:match, avg 2µs/call
562 push @new, $num;
563 }
564 }
565 $self->{'size'} = \@new if @new; # only set if all OK
566 }
567
568 return wantarray
569 ? @{ $self->{'size'} || [0] }
570 : join( ',', @{ $self->{'size'} || [0] } )
571 ;
572}
573
574# ----------------------------------------------------------------------
575
# spent 4.01ms (2.71+1.30) within SQL::Translator::Schema::Field::table which was called 1161 times, avg 3µs/call: # 240 times (1.47ms+1.30ms) by SQL::Translator::Schema::Object::init at line 104 of SQL/Translator/Schema/Object.pm, avg 12µs/call # 240 times (361µs+0s) by SQL::Translator::Producer::SQLite::create_field at line 297 of SQL/Translator/Producer/SQLite.pm, avg 2µs/call # 240 times (321µs+0s) by SQL::Translator::Schema::Field::is_foreign_key at line 306, avg 1µs/call # 240 times (292µs+0s) by SQL::Translator::Schema::Field::name at line 472, avg 1µs/call # 201 times (266µs+0s) by SQL::Translator::Schema::Field::is_primary_key at line 383, avg 1µs/call
sub table {
576
577=pod
578
579=head2 table
580
581Get or set the field's table object. As the table object stringifies this can
582also be used to get the table name.
583
584 my $table = $field->table;
585 print "Table name: $table";
586
587=cut
588
58934832.94ms my $self = shift;
590480778µs2401.11ms if ( my $arg = shift ) {
# spent 1.11ms making 240 calls to SQL::Translator::Schema::Table::__ANON__[SQL/Translator/Schema/Table.pm:59], avg 5µs/call
591240191µs return $self->error('Not a table object') unless
# spent 191µs making 240 calls to UNIVERSAL::isa, avg 795ns/call
592 UNIVERSAL::isa( $arg, 'SQL::Translator::Schema::Table' );
593 $self->{'table'} = $arg;
594 }
595
596 return $self->{'table'};
597}
598
599sub parsed_field {
600
601=head2
602
603Returns the field exactly as the parser found it
604
605=cut
606
607 my $self = shift;
608
609 if (@_) {
610 my $value = shift;
611 $self->{parsed_field} = $value;
612 return $value || $self;
613 }
614 return $self->{parsed_field} || $self;
615}
616
617# ----------------------------------------------------------------------
618sub equals {
619
620=pod
621
622=head2 equals
623
624Determines if this field is the same as another
625
626 my $isIdentical = $field1->equals( $field2 );
627
628=cut
629
630 my $self = shift;
631 my $other = shift;
632 my $case_insensitive = shift;
633
634 return 0 unless $self->SUPER::equals($other);
635 return 0 unless $case_insensitive ? uc($self->name) eq uc($other->name) : $self->name eq $other->name;
636
637 # Comparing types: use sql_data_type if both are not 0. Else use string data_type
638 if ($self->sql_data_type && $other->sql_data_type) {
639 return 0 unless $self->sql_data_type == $other->sql_data_type
640 } else {
641 return 0 unless lc($self->data_type) eq lc($other->data_type)
642 }
643
644 return 0 unless $self->size eq $other->size;
645
646 {
647 my $lhs = $self->default_value;
648 $lhs = \'NULL' unless defined $lhs;
649 my $lhs_is_ref = ! ! ref $lhs;
650
651 my $rhs = $other->default_value;
652 $rhs = \'NULL' unless defined $rhs;
653 my $rhs_is_ref = ! ! ref $rhs;
654
655 # If only one is a ref, fail. -- rjbs, 2008-12-02
656 return 0 if $lhs_is_ref xor $rhs_is_ref;
657
658 my $effective_lhs = $lhs_is_ref ? $$lhs : $lhs;
659 my $effective_rhs = $rhs_is_ref ? $$rhs : $rhs;
660
661 return 0 if $effective_lhs ne $effective_rhs;
662 }
663
664 return 0 unless $self->is_nullable eq $other->is_nullable;
665# return 0 unless $self->is_unique eq $other->is_unique;
666 return 0 unless $self->is_primary_key eq $other->is_primary_key;
667# return 0 unless $self->is_foreign_key eq $other->is_foreign_key;
668 return 0 unless $self->is_auto_increment eq $other->is_auto_increment;
669# return 0 unless $self->comments eq $other->comments;
670 return 0 unless $self->_compare_objects(scalar $self->extra, scalar $other->extra);
671 return 1;
672}
673
674# ----------------------------------------------------------------------
675sub DESTROY {
676#
677# Destroy cyclical references.
678#
679 my $self = shift;
680 undef $self->{'table'};
681 undef $self->{'foreign_key_reference'};
682}
683
684111µs1;
685
686# ----------------------------------------------------------------------
687
688=pod
689
690=head1 AUTHOR
691
692Ken Youens-Clark E<lt>kclark@cpan.orgE<gt>.
693
694=cut
 
# spent 656µs within SQL::Translator::Schema::Field::CORE:match which was called 480 times, avg 1µs/call: # 240 times (393µs+0s) by SQL::Translator::Schema::Field::size at line 561, avg 2µs/call # 240 times (263µs+0s) by SQL::Translator::Schema::Field::order at line 511, avg 1µs/call
sub SQL::Translator::Schema::Field::CORE:match; # opcode