| Filename | /2home/ss5/perl5/perlbrew/perls/perl-5.12.3/lib/site_perl/5.12.3/SQL/Translator/Producer.pm |
| Statements | Executed 1358 statements in 1.68ms |
| Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
|---|---|---|---|---|---|
| 240 | 1 | 1 | 1.40ms | 1.91ms | SQL::Translator::Producer::_apply_default_value |
| 55 | 1 | 1 | 84µs | 84µs | SQL::Translator::Producer::CORE:match (opcode) |
| 1 | 1 | 1 | 14µs | 18µs | SQL::Translator::Producer::BEGIN@21 |
| 1 | 1 | 1 | 8µs | 40µs | SQL::Translator::Producer::BEGIN@22 |
| 1 | 1 | 1 | 4µs | 4µs | SQL::Translator::Producer::BEGIN@23 |
| 0 | 0 | 0 | 0s | 0s | SQL::Translator::Producer::produce |
| Line | State ments |
Time on line |
Calls | Time in subs |
Code |
|---|---|---|---|---|---|
| 1 | package SQL::Translator::Producer; | ||||
| 2 | |||||
| 3 | # ------------------------------------------------------------------- | ||||
| 4 | # Copyright (C) 2002-4 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 | 3 | 21µs | 2 | 22µs | # spent 18µs (14+4) within SQL::Translator::Producer::BEGIN@21 which was called:
# once (14µs+4µs) by SQL::Translator::BEGIN@38 at line 21 # spent 18µs making 1 call to SQL::Translator::Producer::BEGIN@21
# spent 4µs making 1 call to strict::import |
| 22 | 3 | 20µs | 2 | 72µs | # spent 40µs (8+32) within SQL::Translator::Producer::BEGIN@22 which was called:
# once (8µs+32µs) by SQL::Translator::BEGIN@38 at line 22 # spent 40µs making 1 call to SQL::Translator::Producer::BEGIN@22
# spent 32µs making 1 call to vars::import |
| 23 | 3 | 231µs | 1 | 4µs | # spent 4µs within SQL::Translator::Producer::BEGIN@23 which was called:
# once (4µs+0s) by SQL::Translator::BEGIN@38 at line 23 # spent 4µs making 1 call to SQL::Translator::Producer::BEGIN@23 |
| 24 | 1 | 700ns | $VERSION = '1.59'; | ||
| 25 | |||||
| 26 | sub produce { "" } | ||||
| 27 | |||||
| 28 | # Do not rely on this if you are not bundled with SQL::Translator. | ||||
| 29 | # -- rjbs, 2008-09-30 | ||||
| 30 | ## $exceptions contains an arrayref of paired values | ||||
| 31 | ## Each pair contains a pattern match or string, and a value to be used as | ||||
| 32 | ## the default if matched. | ||||
| 33 | ## They are special per Producer, and provide support for the old 'now()' | ||||
| 34 | ## default value exceptions | ||||
| 35 | # spent 1.91ms (1.40+510µs) within SQL::Translator::Producer::_apply_default_value which was called 240 times, avg 8µs/call:
# 240 times (1.40ms+510µs) by SQL::Translator::Producer::SQLite::create_field at line 321 of SQL/Translator/Producer/SQLite.pm, avg 8µs/call | ||||
| 36 | 940 | 1.12ms | my (undef, $field, $field_ref, $exceptions) = @_; | ||
| 37 | 240 | 323µs | my $default = $field->default_value; # spent 323µs making 240 calls to SQL::Translator::Schema::Field::default_value, avg 1µs/call | ||
| 38 | return if !defined $default; | ||||
| 39 | |||||
| 40 | 88 | 94µs | if ($exceptions and ! ref $default) { | ||
| 41 | 264 | 153µs | for (my $i = 0; $i < @$exceptions; $i += 2) { | ||
| 42 | my ($pat, $val) = @$exceptions[ $i, $i + 1 ]; | ||||
| 43 | if (ref $pat and $default =~ $pat) { | ||||
| 44 | $default = $val; | ||||
| 45 | last; | ||||
| 46 | } elsif (lc $default eq lc $pat) { | ||||
| 47 | $default = $val; | ||||
| 48 | last | ||||
| 49 | } | ||||
| 50 | } | ||||
| 51 | } | ||||
| 52 | |||||
| 53 | 55 | 81µs | my $type = lc $field->data_type; # spent 81µs making 55 calls to SQL::Translator::Schema::Field::data_type, avg 1µs/call | ||
| 54 | 55 | 84µs | my $is_numeric_datatype = ($type =~ /^(?:(?:big|medium|small|tiny)?int(?:eger)?|decimal|double|float|num(?:ber|eric)?|real)$/); # spent 84µs making 55 calls to SQL::Translator::Producer::CORE:match, avg 2µs/call | ||
| 55 | |||||
| 56 | 55 | 41µs | 13 | 22µs | if (ref $default) { # spent 22µs making 13 calls to Scalar::Util::looks_like_number, avg 2µs/call |
| 57 | $$field_ref .= " DEFAULT $$default"; | ||||
| 58 | } elsif ($is_numeric_datatype && Scalar::Util::looks_like_number ($default) ) { | ||||
| 59 | # we need to check the data itself in addition to the datatype, for basic safety | ||||
| 60 | $$field_ref .= " DEFAULT $default"; | ||||
| 61 | } else { | ||||
| 62 | $$field_ref .= " DEFAULT '$default'"; | ||||
| 63 | } | ||||
| 64 | |||||
| 65 | } | ||||
| 66 | |||||
| 67 | 1 | 2µs | 1; | ||
| 68 | |||||
| 69 | # ------------------------------------------------------------------- | ||||
| 70 | # A burnt child loves the fire. | ||||
| 71 | # Oscar Wilde | ||||
| 72 | # ------------------------------------------------------------------- | ||||
| 73 | |||||
| 74 | =pod | ||||
| 75 | |||||
| 76 | =head1 NAME | ||||
| 77 | |||||
| 78 | SQL::Translator::Producer - describes how to write a producer | ||||
| 79 | |||||
| 80 | =head1 DESCRIPTION | ||||
| 81 | |||||
| 82 | Producer modules designed to be used with SQL::Translator need to | ||||
| 83 | implement a single function, called B<produce>. B<produce> will be | ||||
| 84 | called with the SQL::Translator object from which it is expected to | ||||
| 85 | retrieve the SQL::Translator::Schema object which has been populated | ||||
| 86 | by the parser. It is expected to return a string. | ||||
| 87 | |||||
| 88 | =head1 METHODS | ||||
| 89 | |||||
| 90 | =over 4 | ||||
| 91 | |||||
| 92 | =item produce | ||||
| 93 | |||||
| 94 | =item create_table($table) | ||||
| 95 | |||||
| 96 | =item create_field($field) | ||||
| 97 | |||||
| 98 | =item create_view($view) | ||||
| 99 | |||||
| 100 | =item create_index($index) | ||||
| 101 | |||||
| 102 | =item create_constraint($constraint) | ||||
| 103 | |||||
| 104 | =item create_trigger($trigger) | ||||
| 105 | |||||
| 106 | =item alter_field($from_field, $to_field) | ||||
| 107 | |||||
| 108 | =item add_field($table, $new_field) | ||||
| 109 | |||||
| 110 | =item drop_field($table, $old_field) | ||||
| 111 | |||||
| 112 | =back | ||||
| 113 | |||||
| 114 | =head1 AUTHORS | ||||
| 115 | |||||
| 116 | Darren Chamberlain E<lt>darren@cpan.orgE<gt>, | ||||
| 117 | Ken Y. Clark E<lt>kclark@cpan.orgE<gt>. | ||||
| 118 | |||||
| 119 | =head1 SEE ALSO | ||||
| 120 | |||||
| 121 | perl(1), SQL::Translator, SQL::Translator::Schema. | ||||
| 122 | |||||
| 123 | =cut | ||||
# spent 84µs within SQL::Translator::Producer::CORE:match which was called 55 times, avg 2µs/call:
# 55 times (84µs+0s) by SQL::Translator::Producer::_apply_default_value at line 54, avg 2µs/call |