lib/Form/Sensible/Reflector/MySQL.pm

filter: Statementstmt 27.0% 98 / 363 Branchbran 0.4% 1 / 230 Conditioncond 0.0% 0 / 89 MC/DCmcdc 0.0% 0 / 45 Subroutinesub 50.9% 26 / 51 Podpod 33.3% 1 / 3 totaltotal 16.1% 126 / 781 CC 155 SCAR 67.4
CC
155
Cov
15%
get_field_definition
2538.0
reflect_from
992.0
__ANON__
72.0
CRAP 844.9
↑ Summary
1 11 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 11 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
3  
4 package Form::Sensible::Reflector::MySQL;
5 11 our $VERSION = 0.2;
6  
7 =head1 NAME
8  
9 Form::Sensible::Reflector::MySQL - Create a Form::Sensible object from a MySQL schema
10  
11 =head1 SYNOPSIS
12  
13 use Form::Sensible;
14 use Form::Sensible::Reflector::MySQL;
15 my $reflector = ReflectorMySQL->new();
16 my $form = $reflector->reflect_from($dbh,
17 {
18 form_name => $table_name,
19 information_schema_dbh => DBI->connect(
20 'DBI:mysql:database=information_schema;host=localhost', 'root', 'password',
21 ),
22 # populate => 1,
23 # only_columns => [qw[ id forename surname dob ] ],
24 }
25 );
26 $form->add_field(
27 Form::Sensible::Field::Toggle->new(
28 name => 'Submit form',
29 )
30 );
31 my $renderer = Form::Sensible->get_renderer('HTML');
32 my $html = $renderer->render($form)->complete;
33 exit;
34  
35 =head1 DESCRIPTION
36  
37 This module provides to L<Form::Sensible|Form::Sensible> the ability to simply
38 create from MySQL tables forms whose fields and validators reflect the schema of
39 the database table. Forms can be created empty, or from the value of
40 a specified row. Joins are not supported.
41  
42 =head2 ALPHA SOFTWARE
43  
44 This module is to be considered a pre-release, to gather test feedback
45 and suggestions. It should not be considered stable for a production
46 environment, and its implementation is subject to change.
47  
48 Specifically, type checking of large numberics (specifically doubles)
49 is not well tested, and C<Select> fields (for C<ENUM> and C<SET>)
50 seems to require some updating of C<Form::Sensible> itself.
51  
52 =head2 REPRESENTATION OF THE SCHEMA
53  
54 =head3 FIELD NAMES
55  
56 Field names are taken from column names, or can be taken from column comments
57 (see L</information_schema_dbh> under L</reflect_form>).
58  
59 =head3 REQUIRED FIELDS
60  
61 Fields are marked as required if their database definition contains C<NOT NULL>.
62  
63 =head3 DEFAULT VALUES
64  
65 Default values are, by default, taken from the database - see L</no_db_defaults>, below L</reflect_from>.
66  
67 =head3 FIELD TYPES
68  
69 String and numeric types are mapped to the appropriate L<Form::Sensible::Field> types, with the
70 exceptions described below.
71  
72 B<NB> Numeric fields may only contain numbers with decimal points (C<.>) but not commas.
73 This outght to be locale dependant, but as far as I can tell, MySQL only accepts data in this format
74 (L<http://dev.mysql.com/doc/refman/5.0/en/locale-support.html|http://dev.mysql.com/doc/refman/5.0/en/locale-support.html>).
75  
76 =head4 ENUM AND SET
77  
78 Set and enumeration columns are rendered as C<Select> fields.
79  
80 =head4 BOOLEAN TYPES
81  
82 Boolean fields (L<Form::Sensible::Field::Toggle|Form::Sensible::Field::Toggle>) are expected
83 to be defined in the SQL schema as C<BIT(1)> columns, based on the rationale outlined in
84 comments on the MySQL website
85 (L<http://dev.mysql.com/doc/refman/5.0/en/numeric-types.html>).
86  
87 B<NB> This is in contradiction to the MySQL behaviour of interpreting the declaration of
88 C<BOOLEAN> columns as C<TINYINT(1)>. Support for the latter could be added as a C<Toggle> field,
89 but what would a C<NULL> entry signfiy?
90  
91 The generated L<Form::Sensible::Field::Toggle> has C<on_value> an C<off_value> of C<1> an C<0>, respectively.
92  
93 =head4 BLOB-TYPE COLUMNS
94  
95 These are currently converted to C<Text> and C<LongText> fields. That can of course be changed
96 by the user after the form as been created, but I am open to suggestions on how to better handle them.
97  
98 =head4 TRIGGER
99  
100 No L<Form::Sensible::Field::Trigger|Form::Sensible::Field::Trigger> is added to the form.
101 See L<the SYNOPSIS|SYNOPSIS>, above.
102  
103 =head2 INTERNATIONALISATION
104  
105 See C<lang> under L</reflect_from>.
106  
107 =head1 METHODS
108  
109 =head2 reflect_form
110  
111 ReflectorMySQL->new->reflect_from( $dbh, $options );
112  
113 Creates a form from a MySQL table schema, optionally populating it
114 with data from the table.
115  
116 In the above example, C<$dbh> is a connected database handle, and
117 C<$options> a reference to a hash as follows:
118
119 =over 4
120  
121 =item form_name
122  
123 In keeping with L<Form::Sensible::Reflector|Form::Sensible::Reflector>,
124 this field can hold the name of the table, though that will be over-ridden
125 by any value in C<table_name>.
126  
127 =item table_name
128  
129 The name of the table upon which to reflect, if not supplied in C<form_name>.
130  
131 =item no_db_defaults
132  
133 Optinal. If a true value, will cancel the default behaviour of populating
134 the empty form with any C<DEFAULT> values set in the schema (aside from C<CURRENT_TIMESTAMP>.
135  
136 =item only_columns
137  
138 An anonymous list of the names of columns to use, to override the default behaviour
139 of using all columns.
140  
141 =item populate
142  
143 Optional. If supplied, causes the created form to be populated with data from
144 a row in the table. The value of C<populate> should be a reference to a hash that
145 defines column names and values to be used in the selection of a record.
146 No error checking is performed.
147  
148 =item information_schema_dbh
149  
150 Optional DBH connected to the C<information_schema> database.
151 If supplied, each field's C<display_name> will be set from the C<COMMENT>
152 recorded in the table definition, if available.
153  
154 Field comments are created thus:
155  
156 CREATE TABLE foo (
157 forename VARCHAR(255) NOT NULL COMMENT 'First name'
158 )
159  
160 ALTER TABLE foo CHANGE COLUMN forename
161 forename VARCHAR(255) NOT NULL COMMENT 'Forename'
162  
163 Comments can be viewed with C<SHOW CREATE foo> or as follows:
164  
165 mysql5> USE information_schema;
166 mysql5> SELECT column_name, column_comment FROM COLUMNS WHERE table_name='foo';
167
168 Should L<Form::Sensible::Form|Form::Sensible::Form> one day support a C<display_name> attribute,
169 this method could supply it with the table's C<COMMENT>: at present, that value is stored in
170 the C<form_display_name> field of the caller.
171  
172 =item lang
173  
174 Defines the language of error messages that are not over-rideable using
175 the default means supplied by C<Form::Sensible>. The format should be that
176 used by HTML, as described at L<http://www.w3.org/International/articles/language-tags/>,
177 without hyphenation.
178  
179 The default language is C<enGB>. To use another language, supply another string,
180 and use it to create a namespace such as C<Form::Sensible::Reflector::MySQL::I18N::enGB>
181 that contains hash reference called C<$I18N>. Please see the bottom of this file's
182 source code for the required keys.
183  
184 =back
185  
186 =cut
187  
188 11 ▶use Form::Sensible 0.20012;
Subroutine BEGIN: called CC=1 SCAR=0.0
189 11 ▶use Form::Sensible::Form;
Subroutine BEGIN: called CC=1 SCAR=0.0
190 11 ▶use Form::Sensible::Field;
Subroutine BEGIN: called CC=1 SCAR=0.0
191 11 ▶use Form::Sensible::Field::Trigger;
Subroutine BEGIN: called CC=1 SCAR=0.0
192 11 ▶use DBI;
Subroutine BEGIN: called CC=1 SCAR=0.0
193 11 ▶use DateTime::Format::MySQL;
Subroutine BEGIN: called CC=1 SCAR=0.0
194 11 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
195  
196 =head1 EXPORTS
197  
198 None.
199  
200 =cut
201  
202 # I'd not choose to use Moose on CPAN, or in a module with such a tiny API,
203 # but the other modules in the parent namespace do, so it is only polite
204 # to make a bit of an effort:
205 11 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
206  
207 11 extends 'Form::Sensible::Reflector';
208  
209 11 has 'accepts_multiple' => ( is => 'rw', isa => 'HashRef', init_arg => undef );
210 11 has 'values' => ( is => 'rw', isa => 'HashRef', init_arg => undef );
211 11 has 'defaults' => ( is => 'rw', isa => 'HashRef', init_arg => undef );
212 11 has 'no_db_defaults' => ( is => 'rw', isa => 'Bool', init_arg => undef );
213 11 has 'table_metadata' => ( is => 'rw', isa => 'HashRef', init_arg => undef );
214 11 has 'only_columns' => (is => 'rw', isa => 'HashRef', init_arg => {} );
215 11 has 'i18n' => (is => 'rw', isa => 'HashRef', init_arg => {} );
216 11 has 'form_display_name' => (is => 'rw', isa => 'Str', init_arg => undef );
217  
218 11 __PACKAGE__->meta->make_immutable;
219  
220 11 our $NUMBER_RE = qr/^-?\d+(\.\d+)?$/;
221  
222  
223 # use Log4perl if we have it, otherwise stub:
224 # See Log::Log4perl::FAQ
225 11 ▶BEGIN {
Subroutine BEGIN: called CC=4 SCAR=15.7
226 11 eval { require Log::Log4perl; };
227  
228 # No Log4perl, so hide calls to it: see Log4perl FAQ
229 11 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) { } 11 0 11
230 11 ▶ no strict qw"refs";
Subroutine BEGIN: called CC=1 SCAR=0.0
231 11 ▶ *{__PACKAGE__."::$_"} = sub { } for qw(TRACE DEBUG INFO WARN ERROR FATAL);
Subroutine __ANON__: not called CC=1 SCAR=0.0
232 0 ▶ *{__PACKAGE__."::LOGCONFESS"} = sub { confess @_ };
Subroutine __ANON__: not called CC=1 SCAR=0.4
233 }
234  
235 # Setup log4perl
236 else {
237 11 ▶ no warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
238 11 ▶ no strict qw"refs";
Subroutine BEGIN: called CC=1 SCAR=0.0
239 0 require Log::Log4perl::Level;
240 0 Log::Log4perl::Level->import(__PACKAGE__);
241 0 Log::Log4perl->import(":easy");
242 # Add calls to present in early versions
243 0 ▶ if ($Log::Log4perl::VERSION < 1.11){
Branch: 1 branch
BranchTrueFalseTotal
if ($Log::Log4perl::VERSION < "1.11") 0 0 0
244 0 *{__PACKAGE__."::TRACE"} = *DEBUG;
245 }
246 }
247 }
248  
249  
250 # $options->{populate} = { id1 => value1, idN => valueN }
251 # Validity of supplied column names is not checked.
252 0 ▶sub reflect_from {
Subroutine reflect_from: not called CC=31 SCAR=69.0
Pod undocumented
253 0 my ($self, $dbh, $options) = @_;
254
255 0 ▶ $options->{form_name} = $options->{table_name} if exists $options->{table_name};
Branch: 1 branch
BranchTrueFalseTotal
if exists $options->{"table_name"} 0 0 0
256
257 # See http://www.w3.org/International/articles/language-tags/
258 0 ▶ if (not $options->{lang}){
Branch: 1 branch
BranchTrueFalseTotal
if (not $options->{'lang'}) { } 0 0 0
259 0 $options->{lang} = 'enGB';
260 }
261 else {
262 0 $options->{lang} =~ tr{-}{}s;
263 }
264
265 0 my $i18n = 'Form::Sensible::Reflector::MySQL::I18N::' . $options->{lang} ; # .'.pm';
266 0 eval "require ".$i18n;
267 0 $self->i18n(
268 eval '$'.$i18n.'::I18N'
269 );
270
271 $self->no_db_defaults(
272 0 ▶ (exists $options->{no_db_defaults} and $options->{no_db_defaults})? 1 : 0
Branch: 1 branch
BranchTrueFalseTotal
exists $options->{'no_db_defaults'} && $options->{'no_db_defaults'} ? : 0 0 0
Condition0%0/3
exists $options->{"no_db_defaults"} and $options->{"no_db_defaults"}
!ll&&!rl&&r
000
MC/DC0%0/2
exists $options->{"no_db_defaults"} and $options->{"no_db_defaults"}
exists $options->{"no_db_defaults"} $options->{"no_db_defaults"}
Truth table0%0/3
A and B
A= exists $options->{"no_db_defaults"}B= $options->{"no_db_defaults"}
ABresult
0X0
100
111
273 );
274
275 0 $self->values( {} );
276 0 $self->defaults( {} );
277 $self->only_columns(
278 $options->{only_columns}? {
279 0 ▶ map { $_=>1 } @{ $options->{only_columns} }
Branch: 1 branch
BranchTrueFalseTotal
$options->{'only_columns'} ? : 0 0 0
280 } : {}
281 );
282  
283 0 my $form = $self->SUPER::reflect_from( $dbh, $options );
284  
285 0 my $row;
286 0 ▶ if (exists $options->{populate}){
Branch: 1 branch
BranchTrueFalseTotal
if (exists $options->{"populate"}) 0 0 0
287 LOGCONFESS "options->{populate} must be a hash of column/values used in the WHERE clause of the SELECT statement that populates the form"
288 0 ▶ if not ref $options->{populate} or ref $options->{populate} ne 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
if not ref $options->{"populate"} or ref $options->{"populate"} ne "HASH" 0 0 0
Condition0%0/3
not ref $options->{"populate"} or ref $options->{"populate"} ne "HASH"
l!l&&r!l&&!r
000
MC/DC0%0/2
not ref $options->{"populate"} or ref $options->{"populate"} ne "HASH"
not ref $options->{"populate"} ref $options->{"populate"} ne "HASH"
Truth table0%0/3
not(A) or B
A= not ref $options->{"populate"}B= ref $options->{"populate"} ne "HASH"
ABresult
1X1
011
000
289
290 0 my $cols = scalar keys %{$self->only_columns}?
291 0 ▶ join(',', map {'`'.$_.'`'} @{$options->{only_columns}})
Branch: 1 branch
BranchTrueFalseTotal
scalar keys %{$self->only_columns;} ? : 0 0 0
292 : '*';
293  
294 my $sql = join' ', 'SELECT', $cols, 'FROM',
295 '`' .$form->{name}.'`',
296 'WHERE',
297 join(
298 ' AND ',
299 map {
300 0 '`'.$_ .'`='. $dbh->quote( $options->{populate}->{$_} )
301 0 } keys %{$options->{populate}}
302 );
303 0 DEBUG $sql;
304 0 $row = $dbh->selectrow_hashref( $sql );
305 # DEBUG Dumper $row;
306 0 ▶ undef $row if scalar keys %$row == 0;
Branch: 1 branch
BranchTrueFalseTotal
if scalar keys %$row == 0 0 0 0
307 }
308  
309 0 for my $field ($form->get_fields){
310 0 ▶ next if $field->field_type eq 'trigger';
Branch: 1 branch
BranchTrueFalseTotal
if $field->field_type eq "trigger" 0 0 0
311
312 # Set selectable values for sets and enumerations:
313 0 ▶ if (exists $self->values->{ $field->name }){
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->values->{$field->name}) 0 0 0
314 $field->add_option( $_ => $_ )
315 0 foreach @{ $self->values->{$field->name } };
316 }
317
318 # Allow sets to have more than one value:
319 0 ▶ if (exists $self->{accepts_multiple}->{$field->name} ){
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{"accepts_multiple"}{$field->name}) 0 0 0
320 0 $field->accepts_multiple(1);
321 }
322
323 # DB defaults:
324 0 ▶ if ( $self->defaults->{ $field->name } ){
Branch: 1 branch
BranchTrueFalseTotal
if ($self->defaults->{$field->name}) 0 0 0
325 0 $field->value( $self->defaults->{ $field->name } );
326 }
327  
328 # Select fields (ENUM, SET) are a special case
329 0 ▶ if ($field->{field_type} eq 'select'){
Branch: 1 branch
BranchTrueFalseTotal
if ($field->{"field_type"} eq "select") 0 0 0
330 my @s = exists( $self->accepts_multiple->{$field->name} )?
331 split(/,/,$self->{values}->{$field->name})
332 0 ▶ : $self->{values}->{ $field->name };
Branch: 1 branch
BranchTrueFalseTotal
exists $self->accepts_multiple->{$field->name} ? : 0 0 0
333 }
334
335 # Populate?
336 0 ▶ if (defined $row){
Branch: 1 branch
BranchTrueFalseTotal
if (defined $row) 0 0 0
337 0 ▶ if (exists $self->{values}->{ $field->name }){
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{'values'}{$field->name}) { } 0 0 0
338 0 ▶ if ($field->{field_type} eq 'select'){
Branch: 1 branch
BranchTrueFalseTotal
if ($field->{"field_type"} eq "select") 0 0 0
339 my @s = exists( $self->{accepts_multiple}->{$field->name} )?
340 split(/,/,$row->{$field->name})
341 0 ▶ : $row->{ $field->name };
Branch: 1 branch
BranchTrueFalseTotal
exists $self->{'accepts_multiple'}{$field->name} ? : 0 0 0
342 # Bug in Form::Sensible Select object - requires values
343 0 ▶ $field->value( @s ) if not defined $field->value;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $field->value 0 0 0
344 0 ▶ eval { $field->set_selection( @s ) if @s; };
Branch: 1 branch
BranchTrueFalseTotal
if @s 0 0 0
345 }
346 }
347 else {
348 0 $field->value( $row->{$field->name} );
349 }
350 }
351 } # Next field
352
353 # Connect to the inforation schema to try to get column comments
354 0 ▶ if (exists $options->{information_schema_dbh}){
Branch: 1 branch
BranchTrueFalseTotal
if (exists $options->{"information_schema_dbh"}) 0 0 0
355 my $column_comments = $options->{information_schema_dbh}->selectall_hashref(
356 "SELECT column_name, column_comment FROM COLUMNS WHERE table_name=?",
357 'column_name',
358 {},
359 $form->{name}
360 0 );
361 0 foreach my $i (keys %$column_comments){
362 0 ▶ next if not length $column_comments->{$i}->{column_comment};
Branch: 1 branch
BranchTrueFalseTotal
unless length $column_comments->{$i}{"column_comment"} 0 0 0
363 0 next if scalar keys %{$self->only_columns}
364 0 ▶ and not $self->only_columns->{$form->field($i)->name};
Branch: 1 branch
BranchTrueFalseTotal
if scalar keys %{$self->only_columns;} and not $self->only_columns->{$form->field($i)->name} 0 0 0
Condition0%0/3
scalar keys %{$self->only_columns;} and not $self->only_columns->{$form->field($i)->name}
!ll&&!rl&&r
000
MC/DC0%0/2
scalar keys %{$self->only_columns;} and not $self->only_columns->{$form->field($i)->name}
scalar keys %{$self->only_columns;} not $self->only_columns->{$form->field($i)->name}
Truth table0%0/3
A and not(B)
A= scalar keys %{$self->only_columns;}B= not $self->only_columns->{$form->field($i)->name}
ABresult
0X0
100
111
365 # column_name , column_comment
366 0 ▶ next if not defined $column_comments->{ $form->field( $i )->name };
Branch: 1 branch
BranchTrueFalseTotal
unless defined $$column_comments{$form->field($i)->name} 0 0 0
367 $form->field( $i )->display_name(
368 $column_comments->{ $form->field( $i )->name }->{column_comment}
369 0 );
370 }
371 # form display name:
372 my $n = $options->{information_schema_dbh}->selectrow_array(
373 "SELECT table_comment FROM TABLES WHERE table_name=?",
374 {},
375 $form->{name}
376 0 );
377 # See http://www.cpantesters.org/cpan/report/921265d4-5157-11e0-9084-0c635704ce1c
378 # ; InnoDB free: 52224 kB
379 0 $n =~ s/;\sInnoDB\sfree:\s\d+\s.B$//;
380 0 $self->form_display_name( $n );
381 }
382
383 0 return $form;
384 }
385  
386  
387 =head2 get_fieldnames
388  
389 Private method inherited from L<Form::Sensible::Reflector|Form::Sensible::Reflector>.
390  
391 =cut
392  
393 0 ▶sub get_fieldnames {
Subroutine get_fieldnames: not called CC=3 SCAR=24.8
Pod documented
394 0 my ($self, $form, $dbh) = @_;
395  
396 # Make sure a table name was supplied
397 LOGCONFESS "Argument one, the form object, should contain a name that represents the name of the table to reflect"
398 0 ▶ if not defined $form->{name};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $form->{"name"} 0 0 0
399
400 # Collect and store metadata from MySQL
401 $self->{table_metadata}->{ $form->{name} } =
402 $dbh->selectall_hashref(
403 0 'describe `' . $form->{name} .'`',
404 'Field'
405 );
406  
407 0 my @rv;
408 0 ▶ if ( scalar keys %{ $self->{only_columns} } ){
Branch: 1 branch
BranchTrueFalseTotal
if (scalar keys %{$$self{'only_columns'};}) { } 0 0 0
409 @rv = grep {
410 0 exists $self->{only_columns}->{$_}
411 0 } keys %{ $self->{table_metadata}->{ $form->{name} } };
412 }
413 else {
414 0 @rv = keys %{ $self->{table_metadata}->{ $form->{name} } };
415 }
416
417 0 return @rv;
418 }
419  
420  
421 # Should numbers be allowed to contain commas?
422 0 ▶sub get_field_definition {
Subroutine get_field_definition: not called CC=55 SCAR=78.4
Pod undocumented
423 0 my ($self, $form, $dbh, $fieldname) = @_;
424 0 my $mysql_type = $self->{table_metadata}->{ $form->{name} }->{$fieldname}->{Type};
425 0 DEBUG $fieldname .': '.$mysql_type;
426 0 my $f = {
427 name => $fieldname,
428 field_class => 'Number'
429 };
430  
431 # db defaults - not no_db_defaults
432 0 ▶ if ( not( $self->no_db_defaults )
Branch: 1 branch
BranchTrueFalseTotal
if (not $self->no_db_defaults and $self->{"table_metadata"}{$form->{"name"}}{$fieldname}{"Default"} and $mysql_type ne "timestamp") 0 0 0
Condition0%0/6
not $self->no_db_defaults and $self->{"table_metadata"}{$form->{"name"}}{$fieldname}{"Default"} and $mysql_type ne "timestamp"
!ll&&!rl&&r
000
not $self->no_db_defaults and $self->{"table_metadata"}{$form->{"name"}}{$fieldname}{"Default"}
!ll&&!rl&&r
000
MC/DC0%0/3
not $self->no_db_defaults and $self->{"table_metadata"}{$form->{"name"}}{$fieldname}{"Default"} and $mysql_type ne "timestamp"
not $self->no_db_defaults $self->{"table_metadata"}{$form->{"name"}}{$fieldname}{"Default"} $mysql_type ne "timestamp"
Truth table0%0/4
not(A) and B and C
A= not $self->no_db_defaultsB= $self->{"table_metadata"}{$form->{"name"}}{$fieldname}{"Default"}C= $mysql_type ne "timestamp"
ABCresult
0XX0
10X0
1100
1111
433 and $self->{table_metadata}->{ $form->{name} }->{$fieldname}->{Default}
434 and $mysql_type ne 'timestamp' # avoid a value of CURRENT_TIMESTAMP
435 ){
436 $self->{defaults}->{$fieldname} =
437 0 $self->{table_metadata}->{ $form->{name} }->{$fieldname}->{Default};
438 0 DEBUG "Set $fieldname to default ", $self->{defaults}->{$fieldname};
439 }
440  
441 # Numeric types - http://dev.mysql.com/doc/refman/5.0/en/numeric-types.html
442 # NB display width with zero-padding for INT(M) -
443 # Cf http://alexander.kirk.at/2007/08/24/what-does-size-in-intsize-of-mysql-mean/
444 0 ▶ if ($mysql_type =~ /^tinyint/){
Branch: 27 branches
BranchTrueFalseTotal
if ($mysql_type =~ /^tinyint/) { } 0 0 0
elsif ($mysql_type =~ /^smallint/) { } 0 0 0
elsif ($mysql_type =~ /^mediumint/) { } 0 0 0
elsif ($mysql_type =~ /^int/) { } 0 0 0
elsif ($mysql_type =~ /^bigint/) { } 0 0 0
elsif ($mysql_type =~ /^(double|real)/) { } 0 0 0
elsif ($mysql_type =~ /^(decimal|numeric) (?: \((\d+) (?:,(\d+))? \) )?$/x) { } 0 0 0
elsif ($mysql_type =~ /^(float|double precision)/) { } 0 0 0
elsif ($mysql_type =~ /^bit\(1\)/) { } 0 0 0
elsif ($mysql_type =~ /^bit\((\d+)\)/) { } 0 0 0
elsif ($mysql_type =~ /datetime$/) { } 0 0 0
elsif ($mysql_type =~ /timestamp/) { } 0 0 0
elsif ($mysql_type eq 'date') { } 0 0 0
elsif ($mysql_type eq 'time') { } 0 0 0
elsif ($mysql_type =~ /year/) { } 0 0 0
elsif ($mysql_type =~ /^(var)?char\((\d+)\)$/) { } 0 0 0
elsif ($mysql_type eq 'tinytext') { } 0 0 0
elsif ($mysql_type eq 'text') { } 0 0 0
elsif ($mysql_type eq 'mediumtext') { } 0 0 0
elsif ($mysql_type eq 'longtext') { } 0 0 0
elsif ($mysql_type =~ /^(var)?binary\((\d+)\)$/) { } 0 0 0
elsif ($mysql_type eq 'tinyblob') { } 0 0 0
elsif ($mysql_type eq 'blob') { } 0 0 0
elsif ($mysql_type eq 'mediumblob') { } 0 0 0
elsif ($mysql_type eq 'longblob') { } 0 0 0
elsif ($mysql_type =~ /^enum\((.*?)\)$/) { } 0 0 0
elsif ($mysql_type =~ /^set\((.*?)\)$/) { } 0 0 0
445 0 $f->{integer_only} = 1;
446 0 ▶ $f->{lower_bound} = $mysql_type =~ /unsigned/? 0 : -128;
Branch: 1 branch
BranchTrueFalseTotal
$mysql_type =~ /unsigned/ ? : 0 0 0
447 0 ▶ $f->{upper_bound} = $mysql_type =~ /unsigned/? 255 : 127;
Branch: 1 branch
BranchTrueFalseTotal
$mysql_type =~ /unsigned/ ? : 0 0 0
448 }
449 elsif ($mysql_type =~ /^smallint/){
450 0 $f->{integer_only} = 1;
451 0 ▶ $f->{lower_bound} = $mysql_type =~ /unsigned/? 0 : -32768;
Branch: 1 branch
BranchTrueFalseTotal
$mysql_type =~ /unsigned/ ? : 0 0 0
452 0 ▶ $f->{upper_bound} = $mysql_type =~ /unsigned/? 65535 : 32767;
Branch: 1 branch
BranchTrueFalseTotal
$mysql_type =~ /unsigned/ ? : 0 0 0
453 }
454 elsif ($mysql_type =~ /^mediumint/){
455 0 $f->{integer_only} = 1;
456 0 ▶ $f->{lower_bound} = $mysql_type =~ /unsigned/? 0 : -8388608;
Branch: 1 branch
BranchTrueFalseTotal
$mysql_type =~ /unsigned/ ? : 0 0 0
457 0 ▶ $f->{upper_bound} = $mysql_type =~ /unsigned/? 16777215 : 8388607;
Branch: 1 branch
BranchTrueFalseTotal
$mysql_type =~ /unsigned/ ? : 0 0 0
458 }
459 elsif ($mysql_type =~ /^int/){
460 0 $f->{integer_only} = 1;
461 0 ▶ $f->{lower_bound} = $mysql_type =~ /unsigned/? 0 : -2147483648;
Branch: 1 branch
BranchTrueFalseTotal
$mysql_type =~ /unsigned/ ? : 0 0 0
462 0 ▶ $f->{upper_bound} = $mysql_type =~ /unsigned/? 4294967295 : 2147483647;
Branch: 1 branch
BranchTrueFalseTotal
$mysql_type =~ /unsigned/ ? : 0 0 0
463 }
464
465 # Treat massive integers as strings or nothing works
466 elsif ($mysql_type =~ /^bigint/){
467 0 $f->{field_type} = 'Text';
468 $f->{validation} = { code => $mysql_type =~ /unsigned/ ?
469 0 ▶ sub {
Subroutine __ANON__: not called CC=5 SCAR=29.4
470 11 ▶ use Math::BigInt;
Subroutine BEGIN: called CC=1 SCAR=0.0
471 0 my $n = Math::BigInt->new( $_[0] );
472 # return '_FIELDNAME_ is an invalid unsigned big integer' if $n eq 'NaN';
473 0 ▶ return $self->i18n->{ubigint}->{nan} if $n eq 'NaN';
Branch: 1 branch
BranchTrueFalseTotal
if $n eq "NaN" 0 0 0
474 0 ▶ return $self->i18n->{ubigint}->{not_int} if not $n->is_int;
Branch: 1 branch
BranchTrueFalseTotal
unless $n->is_int 0 0 0
475 0 ▶ return $self->i18n->{ubigint}->{too_high} if $n > 8446744073709551615;
Branch: 1 branch
BranchTrueFalseTotal
if $n > '8446744073709551615' 0 0 0
476 0 ▶ return $self->i18n->{ubigint}->{too_low} if $n < 0;
Branch: 1 branch
BranchTrueFalseTotal
if $n < 0 0 0 0
477 0 return 0;
478 }
479 0 ▶ : sub {
Subroutine __ANON__: not called CC=5 SCAR=29.4
480 11 ▶ use Math::BigInt ':constant';
Subroutine BEGIN: called CC=1 SCAR=0.0
481 0 my $n = Math::BigInt->new( $_[0] );
482 0 ▶ return $self->i18n->{sbigint}->{nan} if $n eq 'NaN';
Branch: 1 branch
BranchTrueFalseTotal
if $n eq "NaN" 0 0 0
483 0 ▶ return $self->i18n->{sbigint}->{not_int} if not $n->is_int;
Branch: 1 branch
BranchTrueFalseTotal
unless $n->is_int 0 0 0
484 0 ▶ return $self->i18n->{sbigint}->{too_high} if $n > 9223372036854775807;
Branch: 1 branch
BranchTrueFalseTotal
if $n > bless( {"sign" => "+","value" => bless( [854775807,223372036,9], 'Math::BigInt::Calc' )}, 'Math::BigInt' ) 0 0 0
485 0 ▶ return $self->i18n->{sbigint}->{too_low} if $n < -9223372036854775808;
Branch: 1 branch
BranchTrueFalseTotal
if $n < bless( {"sign" => "-","value" => bless( [854775808,223372036,9], 'Math::BigInt::Calc' )}, 'Math::BigInt' ) 0 0 0
486 0 return 0;
487 }
488 0 ▶ };
Branch: 1 branch
BranchTrueFalseTotal
$mysql_type =~ /unsigned/ ? : 0 0 0
489 }
490  
491 elsif ($mysql_type =~ /^(double|real)/){
492 0 $f->{field_type} = 'Text';
493 0 ▶ $f->{validation} = { code => sub {
Subroutine __ANON__: not called CC=7 SCAR=36.7
494 11 ▶ use Math::BigFloat ':constant';
Subroutine BEGIN: called CC=1 SCAR=0.0
495 0 my $n = Math::BigFloat->new( $_[0] );
496 0 ▶ return $self->i18n->{double}->{nan} if $n eq 'NaN';
Branch: 1 branch
BranchTrueFalseTotal
if $n eq "NaN" 0 0 0
497 return $self->i18n->{double}->{oob}
498 0 ▶ if ($n <= -1.7976931348623157E+308 and $n >= -2.2250738585072014E-308)
Branch: 1 branch
BranchTrueFalseTotal
if $n <= bless( {"_e" => bless( [292], 'Math::BigInt::Calc' ),"_es" => "+","_m" => bless( [348623157,17976931], 'Math::BigInt::Calc' ),"sign" => "-"}, 'Math::BigFloat' ) and $n >= bless( {"_e" => bless( [324], 'Math::BigInt::Calc' ),"_es" => "-","_m" => bless( [585072014,22250738], 'Math::BigInt::Calc' ),"sign" => "-"}, 'Math::BigFloat' ) or $n == bless( {"_e" => bless( [0], 'Math::BigInt::Calc' ),"_es" => "+","_m" => bless( [0], 'Math::BigInt::Calc' ),"sign" => "+"}, 'Math::BigFloat' ) or $n <= bless( {"_e" => bless( [324], 'Math::BigInt::Calc' ),"_es" => "-","_m" => bless( [585072014,22250738], 'Math::BigInt::Calc' ),"sign" => "+"}, 'Math::BigFloat' ) and $n >= bless( {"_e" => bless( [3064], 'Math::BigInt::Calc' ),"_es" => "+","_m" => bless( [348623157,17976931], 'Math::BigInt::Calc' ),"sign" => "+"}, 'Math::BigFloat' ) 0 0 0
Condition0%0/12
$n <= bless( {"_e" => bless( [292], 'Math::BigInt::Calc' ),"_es" => "+","_m" => bless( [348623157,17976931], 'Math::BigInt::Calc' ),"sign" => "-"}, 'Math::BigFloat' ) and $n >= bless( {"_e" => bless( [324], 'Math::BigInt::Calc' ),"_es" => "-","_m" => bless( [585072014,22250738], 'Math::BigInt::Calc' ),"sign" => "-"}, 'Math::BigFloat' ) or $n == bless( {"_e" => bless( [0], 'Math::BigInt::Calc' ),"_es" => "+","_m" => bless( [0], 'Math::BigInt::Calc' ),"sign" => "+"}, 'Math::BigFloat' ) or $n <= bless( {"_e" => bless( [324], 'Math::BigInt::Calc' ),"_es" => "-","_m" => bless( [585072014,22250738], 'Math::BigInt::Calc' ),"sign" => "+"}, 'Math::BigFloat' ) and $n >= bless( {"_e" => bless( [3064], 'Math::BigInt::Calc' ),"_es" => "+","_m" => bless( [348623157,17976931], 'Math::BigInt::Calc' ),"sign" => "+"}, 'Math::BigFloat' )
l!l&&r!l&&!r
000
$n <= bless( {"_e" => bless( [292], 'Math::BigInt::Calc' ),"_es" => "+","_m" => bless( [348623157,17976931], 'Math::BigInt::Calc' ),"sign" => "-"}, 'Math::BigFloat' ) and $n >= bless( {"_e" => bless( [324], 'Math::BigInt::Calc' ),"_es" => "-","_m" => bless( [585072014,22250738], 'Math::BigInt::Calc' ),"sign" => "-"}, 'Math::BigFloat' ) or $n == bless( {"_e" => bless( [0], 'Math::BigInt::Calc' ),"_es" => "+","_m" => bless( [0], 'Math::BigInt::Calc' ),"sign" => "+"}, 'Math::BigFloat' )
l!l&&r!l&&!r
000
$n <= bless( {"_e" => bless( [292], 'Math::BigInt::Calc' ),"_es" => "+","_m" => bless( [348623157,17976931], 'Math::BigInt::Calc' ),"sign" => "-"}, 'Math::BigFloat' ) and $n >= bless( {"_e" => bless( [324], 'Math::BigInt::Calc' ),"_es" => "-","_m" => bless( [585072014,22250738], 'Math::BigInt::Calc' ),"sign" => "-"}, 'Math::BigFloat' )
!ll&&!rl&&r
000
$n <= bless( {"_e" => bless( [324], 'Math::BigInt::Calc' ),"_es" => "-","_m" => bless( [585072014,22250738], 'Math::BigInt::Calc' ),"sign" => "+"}, 'Math::BigFloat' ) and $n >= bless( {"_e" => bless( [3064], 'Math::BigInt::Calc' ),"_es" => "+","_m" => bless( [348623157,17976931], 'Math::BigInt::Calc' ),"sign" => "+"}, 'Math::BigFloat' )
!ll&&!rl&&r
000
MC/DC0%0/5
$n <= bless( {"_e" => bless( [292], 'Math::BigInt::Calc' ),"_es" => "+","_m" => bless( [348623157,17976931], 'Math::BigInt::Calc' ),"sign" => "-"}, 'Math::BigFloat' ) and $n >= bless( {"_e" => bless( [324], 'Math::BigInt::Calc' ),"_es" => "-","_m" => bless( [585072014,22250738], 'Math::BigInt::Calc' ),"sign" => "-"}, 'Math::BigFloat' ) or $n == bless( {"_e" => bless( [0], 'Math::BigInt::Calc' ),"_es" => "+","_m" => bless( [0], 'Math::BigInt::Calc' ),"sign" => "+"}, 'Math::BigFloat' ) or $n <= bless( {"_e" => bless( [324], 'Math::BigInt::Calc' ),"_es" => "-","_m" => bless( [585072014,22250738], 'Math::BigInt::Calc' ),"sign" => "+"}, 'Math::BigFloat' ) and $n >= bless( {"_e" => bless( [3064], 'Math::BigInt::Calc' ),"_es" => "+","_m" => bless( [348623157,17976931], 'Math::BigInt::Calc' ),"sign" => "+"}, 'Math::BigFloat' )
$n <= bless( {"_e" => bless( [292], 'Math::BigInt::Calc' ),"_es" => "+","_m" => bless( [348623157,17976931], 'Math::BigInt::Calc' ),"sign" => "-"}, 'Math::BigFloat' ) $n >= bless( {"_e" => bless( [324], 'Math::BigInt::Calc' ),"_es" => "-","_m" => bless( [585072014,22250738], 'Math::BigInt::Calc' ),"sign" => "-"}, 'Math::BigFloat' ) $n == bless( {"_e" => bless( [0], 'Math::BigInt::Calc' ),"_es" => "+","_m" => bless( [0], 'Math::BigInt::Calc' ),"sign" => "+"}, 'Math::BigFloat' ) $n <= bless( {"_e" => bless( [324], 'Math::BigInt::Calc' ),"_es" => "-","_m" => bless( [585072014,22250738], 'Math::BigInt::Calc' ),"sign" => "+"}, 'Math::BigFloat' ) $n >= bless( {"_e" => bless( [3064], 'Math::BigInt::Calc' ),"_es" => "+","_m" => bless( [348623157,17976931], 'Math::BigInt::Calc' ),"sign" => "+"}, 'Math::BigFloat' )
Truth table0%0/9
A and B or C or D and E
A= $n <= bless( {"_e" => bless( [292], 'Math::BigInt::Calc' ),"_es" => "+","_m" => bless( [348623157,17976931], 'Math::BigInt::Calc' ),"sign" => "-"}, 'Math::BigFloat' )B= $n >= bless( {"_e" => bless( [324], 'Math::BigInt::Calc' ),"_es" => "-","_m" => bless( [585072014,22250738], 'Math::BigInt::Calc' ),"sign" => "-"}, 'Math::BigFloat' )C= $n == bless( {"_e" => bless( [0], 'Math::BigInt::Calc' ),"_es" => "+","_m" => bless( [0], 'Math::BigInt::Calc' ),"sign" => "+"}, 'Math::BigFloat' )D= $n <= bless( {"_e" => bless( [324], 'Math::BigInt::Calc' ),"_es" => "-","_m" => bless( [585072014,22250738], 'Math::BigInt::Calc' ),"sign" => "+"}, 'Math::BigFloat' )E= $n >= bless( {"_e" => bless( [3064], 'Math::BigInt::Calc' ),"_es" => "+","_m" => bless( [348623157,17976931], 'Math::BigInt::Calc' ),"sign" => "+"}, 'Math::BigFloat' )
ABCDEresult
11XXX1
0X1XX1
101XX1
0X0111
100111
0X00X0
0X0100
1000X0
100100
499 or $n== 0
500 or ($n <= 2.2250738585072014E-308 and $n >= 1.7976931348623157E+3080);
501 0 return 0;
502 }
503 0 };
504 }
505
506 elsif ($mysql_type =~ /^(decimal|numeric) (?: \((\d+) (?:,(\d+))? \) )?$/x ){
507 0 my ($m, $d) = ($2, $3);
508 # $m apprently includes the decimal point:
509 0 ▶ $m = 0 if $m < 0;
Branch: 1 branch
BranchTrueFalseTotal
if $m < 0 0 0 0
510 0 ▶ $m ||= 65; # But not in 5.0.3-5.0.5, when is 64
Condition0%0/2
$m ||= 65
l!l
00
MC/DC0%0/1
$m ||= 65
$m
Truth table0%0/2
A
A= $m
Aresult
11
00
511 0 ▶ $d ||= 0;
Condition0%0/2
$d ||= 0
l!l
00
MC/DC0%0/1
$d ||= 0
$d
Truth table0%0/2
A
A= $d
Aresult
11
00
512 0 $f->{field_type} = 'Text';
513 0 ▶ $f->{validation} = { code => sub {
Subroutine __ANON__: not called CC=8 SCAR=42.8
514 # Naively assume it's a nice decimal/number
515 0 my ($mym, $myd) = $_[0] =~ /^(\d+) (?: \. (\d+) )?$/x;
516 0 ▶ $mym ||= 0;
Condition0%0/2
$mym ||= 0
l!l
00
MC/DC0%0/1
$mym ||= 0
$mym
Truth table0%0/2
A
A= $mym
Aresult
11
00
517 0 ▶ $myd ||= 0;
Condition0%0/2
$myd ||= 0
l!l
00
MC/DC0%0/1
$myd ||= 0
$myd
Truth table0%0/2
A
A= $myd
Aresult
11
00
518 return $self->i18n->{decimal}->{nan}
519 0 ▶ if not $mym and not $myd and $_[0] !~ /^0*(\.0+)?$/x;
Branch: 1 branch
BranchTrueFalseTotal
unless $mym or $myd or $_[0] =~ /^0*(\.0+)?$/x 0 0 0
Condition0%0/6
$mym or $myd or $_[0] =~ /^0*(\.0+)?$/x
l!l&&r!l&&!r
000
$mym or $myd
l!l&&r!l&&!r
000
MC/DC0%0/3
$mym or $myd or $_[0] =~ /^0*(\.0+)?$/x
$mym $myd $_[0] =~ /^0*(\.0+)?$/x
Truth table0%0/4
A or B or C
A= $mymB= $mydC= $_[0] =~ /^0*(\.0+)?$/x
ABCresult
1XX1
01X1
0011
0000
520 0 ▶ return $self->i18n->{decimal}->{too_long}.$m
Branch: 1 branch
BranchTrueFalseTotal
if length($mym) + length($myd) > $m 0 0 0
521 if (length($mym) + length($myd)) > $m;
522 0 ▶ return $self->i18n->{decimal}->{post_point}.$d
Branch: 1 branch
BranchTrueFalseTotal
if length $myd > $d 0 0 0
523 if length($myd) > $d;
524 0 return 0;
525 }
526 0 };
527 }
528
529 # Floating-Point (Approximate-Value) Types
530 # Defaut range desc at http://help.scibit.com/mascon/masconMySQL_Field_Types.html
531 # and Fixed-Point (Exact-Value) Types
532 elsif ($mysql_type =~ /^(float|double precision)/){
533 0 my ($d, $e);
534  
535 0 ▶ if ($mysql_type =~ /\((\d+),(\d+)\)/){
Branch: 2 branches
BranchTrueFalseTotal
if ($mysql_type =~ /\((\d+),(\d+)\)/) { } 0 0 0
elsif ($mysql_type =~ /^(numeric|decimal)(\((\d+)\))?/) { } 0 0 0
536 0 ($d, $e) = ($1, $2);
537 }
538 elsif ( $mysql_type =~ /^(numeric|decimal)(\((\d+)\))?/ ){
539 0 ($d, $e) = ($2, undef);
540 }
541
542 0 ▶ if (defined $d){
Branch: 1 branch
BranchTrueFalseTotal
if (defined $d) { } 0 0 0
543 0 ▶ my $valid_re = $e?
Branch: 1 branch
BranchTrueFalseTotal
$e ? : 0 0 0
544 qr/^-?\d{1,$d}(\.\d{0,$e})?$/
545 : qr/^-?\d{1,$d}$/;
546 $f->{validation} = {
547 0 ▶ code => sub {
Subroutine __ANON__: not called CC=3 SCAR=24.8
548 0 ▶ return $self->i18n->{float}->{nan} unless $_[0] =~ $NUMBER_RE;
Branch: 1 branch
BranchTrueFalseTotal
unless $_[0] =~ /$Form::Sensible::Reflector::MySQL::NUMBER_RE/ 0 0 0
549 0 ▶ return $self->i18n->{float}->{invalid}.$d if $_[0] !~ $valid_re;
Branch: 1 branch
BranchTrueFalseTotal
unless $_[0] =~ /$valid_re/ 0 0 0
550 0 return 0;
551 }
552 0 };
553 0 my $max = '9' x $d;
554 0 ▶ $max .= '.' . ('9' x $e) if $e;
Branch: 1 branch
BranchTrueFalseTotal
if $e 0 0 0
555 0 $f->{upper_bound} = $max;
556 0 ▶ if ($mysql_type =~ /unsigned/){
Branch: 1 branch
BranchTrueFalseTotal
if ($mysql_type =~ /unsigned/) { } 0 0 0
557 0 $f->{lower_bound} = 0;
558 } else {
559 0 $f->{lower_bound} = - $max;
560 }
561 }
562
563 # No bounds
564 else {
565 0 my $sub;
566 0 ▶ if ($mysql_type eq 'double'){
Branch: 1 branch
BranchTrueFalseTotal
if ($mysql_type eq 'double') { } 0 0 0
567 0 ▶ $sub = sub {
Subroutine __ANON__: not called CC=7 SCAR=36.5
568 11 ▶ use Math::BigFloat ':constant';
Subroutine BEGIN: called CC=1 SCAR=0.0
569 0 my $n = Math::BigFloat->new( $_[0] );
570 0 ▶ return $self->i18n->{float}->{nan} if $n->is_nan;
Branch: 1 branch
BranchTrueFalseTotal
if $n->is_nan 0 0 0
571 return $self->i18n->{float}->{oob} if not(
572 0 ▶ ($n < -1.7976931348623157E+308
Branch: 1 branch
BranchTrueFalseTotal
if not $n < bless( {"_e" => bless( [292], 'Math::BigInt::Calc' ),"_es" => "+","_m" => bless( [348623157,17976931], 'Math::BigInt::Calc' ),"sign" => "-"}, 'Math::BigFloat' ) && $n > bless( {"_e" => bless( [324], 'Math::BigInt::Calc' ),"_es" => "-","_m" => bless( [585072014,22250738], 'Math::BigInt::Calc' ),"sign" => "-"}, 'Math::BigFloat' ) || $n == bless( {"_e" => bless( [0], 'Math::BigInt::Calc' ),"_es" => "+","_m" => bless( [0], 'Math::BigInt::Calc' ),"sign" => "+"}, 'Math::BigFloat' ) || $n >= bless( {"_e" => bless( [324], 'Math::BigInt::Calc' ),"_es" => "-","_m" => bless( [585072014,22250738], 'Math::BigInt::Calc' ),"sign" => "+"}, 'Math::BigFloat' ) && $n <= bless( {"_e" => bless( [292], 'Math::BigInt::Calc' ),"_es" => "+","_m" => bless( [348623157,17976931], 'Math::BigInt::Calc' ),"sign" => "+"}, 'Math::BigFloat' ) 0 0 0
Condition0%0/12
$n < {_e => [292], _es => '+', _m => [348623157, 17976931], sign => '-'} && $n > {_e => [324], _es => '-', _m => [585072014, 22250738], sign => '-'} || $n == {_e => [0], _es => '+', _m => [0], sign => '+'} || $n >= {_e => [324], _es => '-', _m => [585072014, 22250738], sign => '+'} && $n <= {_e => [292], _es => '+', _m => [348623157, 17976931], sign => '+'}
l!l&&r!l&&!r
000
$n < bless( {"_e" => bless( [292], 'Math::BigInt::Calc' ),"_es" => "+","_m" => bless( [348623157,17976931], 'Math::BigInt::Calc' ),"sign" => "-"}, 'Math::BigFloat' ) and $n > bless( {"_e" => bless( [324], 'Math::BigInt::Calc' ),"_es" => "-","_m" => bless( [585072014,22250738], 'Math::BigInt::Calc' ),"sign" => "-"}, 'Math::BigFloat' ) or $n == bless( {"_e" => bless( [0], 'Math::BigInt::Calc' ),"_es" => "+","_m" => bless( [0], 'Math::BigInt::Calc' ),"sign" => "+"}, 'Math::BigFloat' )
l!l&&r!l&&!r
000
$n < bless( {"_e" => bless( [292], 'Math::BigInt::Calc' ),"_es" => "+","_m" => bless( [348623157,17976931], 'Math::BigInt::Calc' ),"sign" => "-"}, 'Math::BigFloat' ) and $n > bless( {"_e" => bless( [324], 'Math::BigInt::Calc' ),"_es" => "-","_m" => bless( [585072014,22250738], 'Math::BigInt::Calc' ),"sign" => "-"}, 'Math::BigFloat' )
!ll&&!rl&&r
000
$n >= bless( {"_e" => bless( [324], 'Math::BigInt::Calc' ),"_es" => "-","_m" => bless( [585072014,22250738], 'Math::BigInt::Calc' ),"sign" => "+"}, 'Math::BigFloat' ) and $n <= bless( {"_e" => bless( [292], 'Math::BigInt::Calc' ),"_es" => "+","_m" => bless( [348623157,17976931], 'Math::BigInt::Calc' ),"sign" => "+"}, 'Math::BigFloat' )
!ll&&!rl&&r
000
MC/DC0%0/5
$n < {_e => [292], _es => '+', _m => [348623157, 17976931], sign => '-'} && $n > {_e => [324], _es => '-', _m => [585072014, 22250738], sign => '-'} || $n == {_e => [0], _es => '+', _m => [0], sign => '+'} || $n >= {_e => [324], _es => '-', _m => [585072014, 22250738], sign => '+'} && $n <= {_e => [292], _es => '+', _m => [348623157, 17976931], sign => '+'}
$n < bless( {"_e" => bless( [292], 'Math::BigInt::Calc' ),"_es" => "+","_m" => bless( [348623157,17976931], 'Math::BigInt::Calc' ),"sign" => "-"}, 'Math::BigFloat' ) $n > bless( {"_e" => bless( [324], 'Math::BigInt::Calc' ),"_es" => "-","_m" => bless( [585072014,22250738], 'Math::BigInt::Calc' ),"sign" => "-"}, 'Math::BigFloat' ) $n == bless( {"_e" => bless( [0], 'Math::BigInt::Calc' ),"_es" => "+","_m" => bless( [0], 'Math::BigInt::Calc' ),"sign" => "+"}, 'Math::BigFloat' ) $n >= bless( {"_e" => bless( [324], 'Math::BigInt::Calc' ),"_es" => "-","_m" => bless( [585072014,22250738], 'Math::BigInt::Calc' ),"sign" => "+"}, 'Math::BigFloat' ) $n <= bless( {"_e" => bless( [292], 'Math::BigInt::Calc' ),"_es" => "+","_m" => bless( [348623157,17976931], 'Math::BigInt::Calc' ),"sign" => "+"}, 'Math::BigFloat' )
Truth table0%0/9
A and B or C || D and E
A= $n < bless( {"_e" => bless( [292], 'Math::BigInt::Calc' ),"_es" => "+","_m" => bless( [348623157,17976931], 'Math::BigInt::Calc' ),"sign" => "-"}, 'Math::BigFloat' )B= $n > bless( {"_e" => bless( [324], 'Math::BigInt::Calc' ),"_es" => "-","_m" => bless( [585072014,22250738], 'Math::BigInt::Calc' ),"sign" => "-"}, 'Math::BigFloat' )C= $n == bless( {"_e" => bless( [0], 'Math::BigInt::Calc' ),"_es" => "+","_m" => bless( [0], 'Math::BigInt::Calc' ),"sign" => "+"}, 'Math::BigFloat' )D= $n >= bless( {"_e" => bless( [324], 'Math::BigInt::Calc' ),"_es" => "-","_m" => bless( [585072014,22250738], 'Math::BigInt::Calc' ),"sign" => "+"}, 'Math::BigFloat' )E= $n <= bless( {"_e" => bless( [292], 'Math::BigInt::Calc' ),"_es" => "+","_m" => bless( [348623157,17976931], 'Math::BigInt::Calc' ),"sign" => "+"}, 'Math::BigFloat' )
ABCDEresult
11XXX1
0X1XX1
101XX1
0X0111
100111
0X00X0
0X0100
1000X0
100100
573 and $n > -2.2250738585072014E-308
574 ) or $n==0
575 or (
576 $n >= 2.2250738585072014E-308
577 and $n <= 1.7976931348623157E+308
578 )
579 );
580 }
581 0 }
582 else {
583 0 ▶ $sub = sub {
Subroutine __ANON__: not called CC=7 SCAR=36.5
584 11 ▶ use Math::BigFloat ':constant';
Subroutine BEGIN: called CC=1 SCAR=0.0
585 0 my $n = Math::BigFloat->new( $_[0] );
586 0 ▶ return $self->i18n->{float}->{nan} if $n->is_nan;
Branch: 1 branch
BranchTrueFalseTotal
if $n->is_nan 0 0 0
587 return $self->i18n->{float}->{oob} if (
588 0 ▶ $n >= -340282346600000016151267322115014000640.000000
Branch: 1 branch
BranchTrueFalseTotal
if $n >= bless( {"_e" => bless( [1], 'Math::BigInt::Calc' ),"_es" => "+","_m" => bless( [501400064,126732211,1615,28234660,34], 'Math::BigInt::Calc' ),"sign" => "-"}, 'Math::BigFloat' ) and $n <= bless( {"_e" => bless( [47], 'Math::BigInt::Calc' ),"_es" => "-","_m" => bless( [175494351,1], 'Math::BigInt::Calc' ),"sign" => "-"}, 'Math::BigFloat' ) or $n == bless( {"_e" => bless( [0], 'Math::BigInt::Calc' ),"_es" => "+","_m" => bless( [0], 'Math::BigInt::Calc' ),"sign" => "+"}, 'Math::BigFloat' ) or $n >= bless( {"_e" => bless( [47], 'Math::BigInt::Calc' ),"_es" => "-","_m" => bless( [175494351,1], 'Math::BigInt::Calc' ),"sign" => "+"}, 'Math::BigFloat' ) and $n <= bless( {"_e" => bless( [1], 'Math::BigInt::Calc' ),"_es" => "+","_m" => bless( [501400064,126732211,1615,28234660,34], 'Math::BigInt::Calc' ),"sign" => "+"}, 'Math::BigFloat' ) 0 0 0
Condition0%0/12
$n >= bless( {"_e" => bless( [1], 'Math::BigInt::Calc' ),"_es" => "+","_m" => bless( [501400064,126732211,1615,28234660,34], 'Math::BigInt::Calc' ),"sign" => "-"}, 'Math::BigFloat' ) and $n <= bless( {"_e" => bless( [47], 'Math::BigInt::Calc' ),"_es" => "-","_m" => bless( [175494351,1], 'Math::BigInt::Calc' ),"sign" => "-"}, 'Math::BigFloat' ) or $n == bless( {"_e" => bless( [0], 'Math::BigInt::Calc' ),"_es" => "+","_m" => bless( [0], 'Math::BigInt::Calc' ),"sign" => "+"}, 'Math::BigFloat' ) or $n >= bless( {"_e" => bless( [47], 'Math::BigInt::Calc' ),"_es" => "-","_m" => bless( [175494351,1], 'Math::BigInt::Calc' ),"sign" => "+"}, 'Math::BigFloat' ) and $n <= bless( {"_e" => bless( [1], 'Math::BigInt::Calc' ),"_es" => "+","_m" => bless( [501400064,126732211,1615,28234660,34], 'Math::BigInt::Calc' ),"sign" => "+"}, 'Math::BigFloat' )
l!l&&r!l&&!r
000
$n >= bless( {"_e" => bless( [1], 'Math::BigInt::Calc' ),"_es" => "+","_m" => bless( [501400064,126732211,1615,28234660,34], 'Math::BigInt::Calc' ),"sign" => "-"}, 'Math::BigFloat' ) and $n <= bless( {"_e" => bless( [47], 'Math::BigInt::Calc' ),"_es" => "-","_m" => bless( [175494351,1], 'Math::BigInt::Calc' ),"sign" => "-"}, 'Math::BigFloat' ) or $n == bless( {"_e" => bless( [0], 'Math::BigInt::Calc' ),"_es" => "+","_m" => bless( [0], 'Math::BigInt::Calc' ),"sign" => "+"}, 'Math::BigFloat' )
l!l&&r!l&&!r
000
$n >= bless( {"_e" => bless( [1], 'Math::BigInt::Calc' ),"_es" => "+","_m" => bless( [501400064,126732211,1615,28234660,34], 'Math::BigInt::Calc' ),"sign" => "-"}, 'Math::BigFloat' ) and $n <= bless( {"_e" => bless( [47], 'Math::BigInt::Calc' ),"_es" => "-","_m" => bless( [175494351,1], 'Math::BigInt::Calc' ),"sign" => "-"}, 'Math::BigFloat' )
!ll&&!rl&&r
000
$n >= bless( {"_e" => bless( [47], 'Math::BigInt::Calc' ),"_es" => "-","_m" => bless( [175494351,1], 'Math::BigInt::Calc' ),"sign" => "+"}, 'Math::BigFloat' ) and $n <= bless( {"_e" => bless( [1], 'Math::BigInt::Calc' ),"_es" => "+","_m" => bless( [501400064,126732211,1615,28234660,34], 'Math::BigInt::Calc' ),"sign" => "+"}, 'Math::BigFloat' )
!ll&&!rl&&r
000
MC/DC0%0/5
$n >= bless( {"_e" => bless( [1], 'Math::BigInt::Calc' ),"_es" => "+","_m" => bless( [501400064,126732211,1615,28234660,34], 'Math::BigInt::Calc' ),"sign" => "-"}, 'Math::BigFloat' ) and $n <= bless( {"_e" => bless( [47], 'Math::BigInt::Calc' ),"_es" => "-","_m" => bless( [175494351,1], 'Math::BigInt::Calc' ),"sign" => "-"}, 'Math::BigFloat' ) or $n == bless( {"_e" => bless( [0], 'Math::BigInt::Calc' ),"_es" => "+","_m" => bless( [0], 'Math::BigInt::Calc' ),"sign" => "+"}, 'Math::BigFloat' ) or $n >= bless( {"_e" => bless( [47], 'Math::BigInt::Calc' ),"_es" => "-","_m" => bless( [175494351,1], 'Math::BigInt::Calc' ),"sign" => "+"}, 'Math::BigFloat' ) and $n <= bless( {"_e" => bless( [1], 'Math::BigInt::Calc' ),"_es" => "+","_m" => bless( [501400064,126732211,1615,28234660,34], 'Math::BigInt::Calc' ),"sign" => "+"}, 'Math::BigFloat' )
$n >= bless( {"_e" => bless( [1], 'Math::BigInt::Calc' ),"_es" => "+","_m" => bless( [501400064,126732211,1615,28234660,34], 'Math::BigInt::Calc' ),"sign" => "-"}, 'Math::BigFloat' ) $n <= bless( {"_e" => bless( [47], 'Math::BigInt::Calc' ),"_es" => "-","_m" => bless( [175494351,1], 'Math::BigInt::Calc' ),"sign" => "-"}, 'Math::BigFloat' ) $n == bless( {"_e" => bless( [0], 'Math::BigInt::Calc' ),"_es" => "+","_m" => bless( [0], 'Math::BigInt::Calc' ),"sign" => "+"}, 'Math::BigFloat' ) $n >= bless( {"_e" => bless( [47], 'Math::BigInt::Calc' ),"_es" => "-","_m" => bless( [175494351,1], 'Math::BigInt::Calc' ),"sign" => "+"}, 'Math::BigFloat' ) $n <= bless( {"_e" => bless( [1], 'Math::BigInt::Calc' ),"_es" => "+","_m" => bless( [501400064,126732211,1615,28234660,34], 'Math::BigInt::Calc' ),"sign" => "+"}, 'Math::BigFloat' )
Truth table0%0/9
A and B or C or D and E
A= $n >= bless( {"_e" => bless( [1], 'Math::BigInt::Calc' ),"_es" => "+","_m" => bless( [501400064,126732211,1615,28234660,34], 'Math::BigInt::Calc' ),"sign" => "-"}, 'Math::BigFloat' )B= $n <= bless( {"_e" => bless( [47], 'Math::BigInt::Calc' ),"_es" => "-","_m" => bless( [175494351,1], 'Math::BigInt::Calc' ),"sign" => "-"}, 'Math::BigFloat' )C= $n == bless( {"_e" => bless( [0], 'Math::BigInt::Calc' ),"_es" => "+","_m" => bless( [0], 'Math::BigInt::Calc' ),"sign" => "+"}, 'Math::BigFloat' )D= $n >= bless( {"_e" => bless( [47], 'Math::BigInt::Calc' ),"_es" => "-","_m" => bless( [175494351,1], 'Math::BigInt::Calc' ),"sign" => "+"}, 'Math::BigFloat' )E= $n <= bless( {"_e" => bless( [1], 'Math::BigInt::Calc' ),"_es" => "+","_m" => bless( [501400064,126732211,1615,28234660,34], 'Math::BigInt::Calc' ),"sign" => "+"}, 'Math::BigFloat' )
ABCDEresult
11XXX1
0X1XX1
101XX1
0X0111
100111
0X00X0
0X0100
1000X0
100100
589 and $n <= -0.000000000000000000000000000000000000011754943510
590 )
591 or $n == 0
592 or ($n >= 0.000000000000000000000000000000000000011754943510
593 and $n <= 340282346600000016151267322115014000640.000000
594 )
595 }
596 0 }
597 $f->{validation} = {
598 0 code => $sub,
599 };
600 }
601 }
602
603
604 # BIT(1) == a true boolean == Toggle field boolean
605 elsif ($mysql_type =~ /^bit\(1\)/){
606 0 $f->{field_class} = 'Toggle';
607 $f->{validation} = {
608 0 ▶ code => sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
609 0 ▶ return $self->i18n->{bit1}->{oob} if $_[0] !~ qr/^[10]$/
Branch: 1 branch
BranchTrueFalseTotal
if not $_[0] =~ qr/^[10]$/ 0 0 0
610 },
611 0 };
612 0 $f->{on_value} = 1;
613 0 $f->{off_value} = 0;
614 }
615
616 # Any other bit type
617 elsif ($mysql_type =~ /^bit\((\d+)\)/){
618 0 my $len = $1;
619 0 $f->{maximum_length} = $len;
620 0 ▶ my $min = $mysql_type =~ /not null/gi? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$mysql_type =~ /not null/gi ? : 0 0 0
621 0 my $re = qr/^[10]{$min,$len}$/;
622 0 $f->{field_class} = 'Text'; # to ignore numeric checks and skip to custom
623 $f->{validation} = {
624 0 ▶ code => sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
625 0 ▶ return $self->i18n->{bits}->{invalid}.$len
Branch: 1 branch
BranchTrueFalseTotal
unless $_[0] =~ /$re/ 0 0 0
626 if $_[0] !~ $re;
627 0 return 0;
628 },
629 0 };
630 }
631
632 # Date/times
633 elsif ($mysql_type =~ /datetime$/ ){
634 0 $f->{field_class} = 'Text';
635 $f->{validation} = {
636 0 ▶ code => sub {
Subroutine __ANON__: not called CC=4 SCAR=30.0
637 0 ▶ return $self->i18n->{datetime}->{year_length} if $_[0] !~ /^(\d{4})/;
Branch: 1 branch
BranchTrueFalseTotal
unless $_[0] =~ /^(\d{4})/ 0 0 0
638 0 ▶ return $self->i18n->{datetime}->{year_oob} if $1 < 1001;
Branch: 1 branch
BranchTrueFalseTotal
if $1 < 1001 0 0 0
639 0 eval { DateTime::Format::MySQL->parse_datetime( $_[0] ) };
640 0 ▶ return $self->i18n->{datetime}->{parser_error_prefix}.$@ || 0;
Condition0%0/2
$self->i18n->{'datetime'}{'parser_error_prefix'} . $@ || 0
l!l
00
MC/DC0%0/1
$self->i18n->{'datetime'}{'parser_error_prefix'} . $@ || 0
$self->i18n->{'datetime'}{'parser_error_prefix'} . $@
Truth table0%0/2
A
A= $self->i18n->{'datetime'}{'parser_error_prefix'} . $@
Aresult
11
00
641 },
642 0 };
643 }
644 elsif ($mysql_type =~ /timestamp/ ){
645 0 $f->{field_class} = 'Text';
646 $f->{validation} = {
647 0 ▶ code => sub {
Subroutine __ANON__: not called CC=4 SCAR=30.0
648 0 ▶ return $self->i18n->{timestamp}->{year_length} if $_[0] !~ /^(\d{4})/;
Branch: 1 branch
BranchTrueFalseTotal
unless $_[0] =~ /^(\d{4})/ 0 0 0
649 0 ▶ return $self->i18n->{timestamp}->{year_oob} if $1 < 1001;
Branch: 1 branch
BranchTrueFalseTotal
if $1 < 1001 0 0 0
650 0 eval { DateTime::Format::MySQL->parse_timestamp( $_[0] ) };
651 0 ▶ return $self->i18n->{timestamp}->{parser_error_prefix} . $@
Condition0%0/2
$self->i18n->{'timestamp'}{'parser_error_prefix'} . $@ || 0
l!l
00
MC/DC0%0/1
$self->i18n->{'timestamp'}{'parser_error_prefix'} . $@ || 0
$self->i18n->{'timestamp'}{'parser_error_prefix'} . $@
Truth table0%0/2
A
A= $self->i18n->{'timestamp'}{'parser_error_prefix'} . $@
Aresult
11
00
652 || 0;
653 },
654 0 };
655 }
656 elsif ($mysql_type eq 'date'){
657 0 $f->{field_class} = 'Text';
658 $f->{validation} = {
659 0 ▶ code => sub {
Subroutine __ANON__: not called CC=4 SCAR=30.0
660 0 ▶ return $self->i18n->{date}->{year_length} if $_[0] !~ /^(\d{4})/;
Branch: 1 branch
BranchTrueFalseTotal
unless $_[0] =~ /^(\d{4})/ 0 0 0
661 0 ▶ return $self->i18n->{date}->{year_oob} if $1 < 1001;
Branch: 1 branch
BranchTrueFalseTotal
if $1 < 1001 0 0 0
662 0 eval { DateTime::Format::MySQL->parse_date( $_[0] ) };
663 0 ▶ return $self->i18n->{date}->{parser_error_prefix}.$@
Condition0%0/2
$self->i18n->{'date'}{'parser_error_prefix'} . $@ || 0
l!l
00
MC/DC0%0/1
$self->i18n->{'date'}{'parser_error_prefix'} . $@ || 0
$self->i18n->{'date'}{'parser_error_prefix'} . $@
Truth table0%0/2
A
A= $self->i18n->{'date'}{'parser_error_prefix'} . $@
Aresult
11
00
664 || 0;
665 },
666 0 };
667 }
668 elsif ($mysql_type eq 'time'){
669 0 $f->{field_class} = 'Text';
670 0 $f->{maximum_length} = 8;
671 $f->{validation} = {
672 0 ▶ code => sub {
Subroutine __ANON__: not called CC=8 SCAR=42.8
673 return $self->i18n->{time}->{invalid}
674 0 ▶ if $_[0] !~ qr/^(\d{2})[-_":\/*,.](\d{2})[-_":\/*,.](\d{2})$/;
Branch: 1 branch
BranchTrueFalseTotal
unless $_[0] =~ qr#^(\d{2})[-_":/*,.](\d{2})[-_":/*,.](\d{2})$# 0 0 0
675 0 ▶ return $self->i18n->{time}->{hours} if $1 < 0 or $1 > 23;
Branch: 1 branch
BranchTrueFalseTotal
if $1 < 0 or $1 > 23 0 0 0
Condition0%0/3
$1 < 0 or $1 > 23
l!l&&r!l&&!r
000
MC/DC0%0/2
$1 < 0 or $1 > 23
$1 < 0 $1 > 23
Truth table0%0/3
A or B
A= $1 < 0B= $1 > 23
ABresult
1X1
011
000
676 0 ▶ return $self->i18n->{time}->{minutes} if $1 < 0 or $2 > 59;
Branch: 1 branch
BranchTrueFalseTotal
if $1 < 0 or $2 > 59 0 0 0
Condition0%0/3
$1 < 0 or $2 > 59
l!l&&r!l&&!r
000
MC/DC0%0/2
$1 < 0 or $2 > 59
$1 < 0 $2 > 59
Truth table0%0/3
A or B
A= $1 < 0B= $2 > 59
ABresult
1X1
011
000
677 0 ▶ return $self->i18n->{time}->{seconds} if $1 < 0 or $3 > 59;
Branch: 1 branch
BranchTrueFalseTotal
if $1 < 0 or $3 > 59 0 0 0
Condition0%0/3
$1 < 0 or $3 > 59
l!l&&r!l&&!r
000
MC/DC0%0/2
$1 < 0 or $3 > 59
$1 < 0 $3 > 59
Truth table0%0/3
A or B
A= $1 < 0B= $3 > 59
ABresult
1X1
011
000
678 }
679 0 };
680 }
681 elsif ($mysql_type =~ /year/){
682 0 $f->{field_class} = 'Text';
683 $f->{validation} = {
684 0 ▶ code => sub {
Subroutine __ANON__: not called CC=6 SCAR=37.4
685 0 ▶ if ($mysql_type =~ /year\(4\)/){
Branch: 1 branch
BranchTrueFalseTotal
if ($mysql_type =~ /year\(4\)/) { } 0 0 0
686 return $self->i18n->{year4}->{oob}
687 0 ▶ if $_[0] !~ qr/^\d{4}$/ or $_[0] < 1901 or $_[0] > 2155;
Branch: 1 branch
BranchTrueFalseTotal
if not $_[0] =~ qr/^\d{4}$/ or $_[0] < 1901 or $_[0] > 2155 0 0 0
Condition0%0/6
not $_[0] =~ qr/^\d{4}$/ or $_[0] < 1901 or $_[0] > 2155
l!l&&r!l&&!r
000
not $_[0] =~ qr/^\d{4}$/ or $_[0] < 1901
l!l&&r!l&&!r
000
MC/DC0%0/3
not $_[0] =~ qr/^\d{4}$/ or $_[0] < 1901 or $_[0] > 2155
not $_[0] =~ qr/^\d{4}$/ $_[0] < 1901 $_[0] > 2155
Truth table0%0/4
not(A) or B or C
A= not $_[0] =~ qr/^\d{4}$/B= $_[0] < 1901C= $_[0] > 2155
ABCresult
1XX1
01X1
0011
0000
688 0 return 0;
689 }
690 else {
691 0 ▶ return $self->i18n->{year}->{oob} if $_[0] !~ qr/^\d{2}$/;
Branch: 1 branch
BranchTrueFalseTotal
unless $_[0] =~ qr/^\d{2}$/ 0 0 0
692 0 return 0;
693 }
694 },
695 0 };
696 }
697
698 # String types - decimal values from http://www.htmlite.com/mysql003.php
699 elsif ($mysql_type =~ /^(var)?char\((\d+)\)$/ ){
700 0 $f->{field_class} = 'Text';
701 0 $f->{maximum_length} = $2;
702 }
703 elsif ($mysql_type eq 'tinytext' ){
704 0 $f->{field_class} = 'Text';
705 0 $f->{maximum_length} = 255;
706 }
707 elsif ($mysql_type eq 'text' ){
708 0 $f->{field_class} = 'LongText';
709 0 $f->{maximum_length} = 65535;
710 }
711 elsif ($mysql_type eq 'mediumtext' ){
712 0 $f->{field_class} = 'LongText';
713 0 $f->{maximum_length} = 16777215;
714 }
715 elsif ($mysql_type eq 'longtext' ){
716 0 $f->{field_class} = 'LongText';
717 0 $f->{maximum_length} = 4294967295;
718 }
719  
720 # length() works on characters unless 'use bytes'
721 elsif ($mysql_type =~ /^(var)?binary\((\d+)\)$/ ){
722 0 $f->{field_class} = 'Text';
723 0 my ($len) = $2;
724 0 ▶ $f->{validation} = { code => sub {
Subroutine __ANON__: not called CC=2 SCAR=10.1
725 11 ▶ use bytes;
Subroutine BEGIN: called CC=1 SCAR=0.0
726 0 ▶ return 0 if length $_[0] <= $len;
Branch: 1 branch
BranchTrueFalseTotal
if length $_[0] <= $len 0 0 0
727 0 return $self->i18n->{binary}->{too_long} . $len;
728 0 } };
729 }
730 elsif ($mysql_type eq 'tinyblob' ){
731 0 $f->{field_class} = 'Text';
732 0 ▶ $f->{validation} = { code => sub {
Subroutine __ANON__: not called CC=2 SCAR=10.1
733 11 ▶ use bytes;
Subroutine BEGIN: called CC=1 SCAR=0.0
734 0 ▶ return 0 if length $_[0] <= 255;
Branch: 1 branch
BranchTrueFalseTotal
if length $_[0] <= 255 0 0 0
735 0 return $self->i18n->{tinyblob}->{too_long};
736 0 } };
737 }
738 elsif ($mysql_type eq 'blob' ){
739 0 $f->{field_class} = 'LongText';
740 0 $f->{maximum_length} = 65535;
741 0 ▶ $f->{validation} = { code => sub {
Subroutine __ANON__: not called CC=2 SCAR=10.1
742 11 ▶ use bytes;
Subroutine BEGIN: called CC=1 SCAR=0.0
743 0 ▶ return 0 if length $_[0] <= 65535;
Branch: 1 branch
BranchTrueFalseTotal
if length $_[0] <= 65535 0 0 0
744 0 return $self->i18n->{blob}->{too_long};
745 0 } };
746 }
747 elsif ($mysql_type eq 'mediumblob' ){
748 0 $f->{field_class} = 'LongText';
749 0 $f->{maximum_length} = 16777215;
750 0 ▶ $f->{validation} = { code => sub {
Subroutine __ANON__: not called CC=2 SCAR=10.1
751 11 ▶ use bytes;
Subroutine BEGIN: called CC=1 SCAR=0.0
752 0 ▶ return 0 if length $_[0] <= 16777215;
Branch: 1 branch
BranchTrueFalseTotal
if length $_[0] <= 16777215 0 0 0
753 0 return $self->i18n->{mediumblob}->{too_long};
754 0 } };
755 }
756 elsif ($mysql_type eq 'longblob' ){
757 0 $f->{field_class} = 'LongText';
758 0 $f->{maximum_length} = 4294967295;
759 0 ▶ $f->{validation} = { code => sub {
Subroutine __ANON__: not called CC=2 SCAR=10.1
760 11 ▶ use bytes;
Subroutine BEGIN: called CC=1 SCAR=0.0
761 0 ▶ return 0 if length $_[0] <= 4294967295;
Branch: 1 branch
BranchTrueFalseTotal
if length $_[0] <= 4294967295 0 0 0
762 0 return $self->i18n->{longblob}->{too_long};
763 0 } };
764 }
765
766 # ENUM
767 elsif ($mysql_type =~ /^enum\((.*?)\)$/){
768 0 $f->{field_class} = 'Select';
769 0 my @re;
770 0 my $vs = $1 .',';
771 0 foreach my $i (split /',/, $vs){
772 # Bug in Form::Sensible Select object
773 # - requires values - Can't add values here, no objects to which to add
774 0 push @{ $self->{values}->{$fieldname} }, substr $i, 1;
775 0 push @re, quotemeta( substr($i,1) );
776 }
777 0 my $re = join '|', @re;
778 $f->{validation} = {
779 0 regex => qr/^($re)$/i
780 };
781 }
782  
783 # SET http://dev.mysql.com/doc/refman/5.0/en/set.html
784 # Value must contain one or more values from the SET
785 elsif ($mysql_type =~ /^set\((.*?)\)$/){
786 0 $f->{field_class} = 'Select';
787 0 $self->{accepts_multiple}->{$fieldname} = 1;
788 0 my @re;
789 0 my $vs = $1 .',';
790 0 foreach my $i (split /',/, $vs){
791 # Bug in Form::Sensible Select object
792 # requires values - Can't add values here, no objects to which to add
793 0 push @{ $self->{values}->{$fieldname} }, substr $i, 1;
794 0 push @re, quotemeta( substr($i,1) );
795 }
796 0 my $re = join '|', @re;
797 0 ▶ $f->{validation} = { code => sub {
Subroutine __ANON__: not called CC=3 SCAR=24.8
798 0 TRACE "$re vs ", join ' / ', @_;
799  
800 0 foreach my $i (split /,/, $_[0]){
801 0 ▶ return 0 if $i !~ /^($re)$/i
Branch: 1 branch
BranchTrueFalseTotal
unless $i =~ /^($re)$/i 0 0 0
802 }
803 0 return 1;
804 0 } };
805 }
806
807 # Is the field required?
808 $f->{validation}->{required} = 1
809 if not defined( $self->{table_metadata}->{ $form->{name} }->{$fieldname}->{Default} )
810 0 ▶ and $self->{table_metadata}->{ $form->{name} }->{$fieldname}->{Null} eq 'NO';
Branch: 1 branch
BranchTrueFalseTotal
if not defined $self->{"table_metadata"}{$form->{"name"}}{$fieldname}{"Default"} and $self->{"table_metadata"}{$form->{"name"}}{$fieldname}{"Null"} eq "NO" 0 0 0
Condition0%0/3
not defined $self->{"table_metadata"}{$form->{"name"}}{$fieldname}{"Default"} and $self->{"table_metadata"}{$form->{"name"}}{$fieldname}{"Null"} eq "NO"
!ll&&!rl&&r
000
MC/DC0%0/2
not defined $self->{"table_metadata"}{$form->{"name"}}{$fieldname}{"Default"} and $self->{"table_metadata"}{$form->{"name"}}{$fieldname}{"Null"} eq "NO"
not defined $self->{"table_metadata"}{$form->{"name"}}{$fieldname}{"Default"} $self->{"table_metadata"}{$form->{"name"}}{$fieldname}{"Null"} eq "NO"
Truth table0%0/3
not(A) and B
A= not defined $self->{"table_metadata"}{$form->{"name"}}{$fieldname}{"Default"}B= $self->{"table_metadata"}{$form->{"name"}}{$fieldname}{"Null"} eq "NO"
ABresult
0X0
100
111
811
812 # warn Dumper $f;
813 0 return $f;
814 }
815  
816  
817  
818 11 1;
819  
820  
821 =head1 DEPENDENCIES
822  
823 L<Moose|Moose>,
824 L<Form::Sensible::Reflector|Form::Sensible::Reflector>,
825 L<Form::Sensible|Form::Sensible>,
826 L<DBD::mysql|DBD::mysql>,
827 L<DateTime::Format::MySQL|DateTime::Format::MySQL>,
828 L<Math::BigInt>.
829  
830 =head1 CAVEAT EMPTORIUM
831  
832 =over 4
833  
834 =item *
835  
836 The C<Math::Big*> modules may help if you use numbers.
837  
838 =item *
839  
840 At the time of writing, the young L<Form::Sensible::Field::Select|Form::Sensible::Field::Select>
841 has a bug which prevents the correct setting of the selected entity, as well as preventing
842 multiple selections. This has been reported and will be fiex in the next release.
843  
844 =item *
845  
846 Numeric fields may not contain commas, as described under L<FIELD TYPES>.
847  
848 =back
849  
850 =head1 BUGS, PATCHES, SUGGESTIONS
851  
852 Please make use of CPAN's Request Tracker.
853  
854 =head1 SEE ALSO
855  
856 The MySQL Manual, L<Chater 10 Data Types|http://dev.mysql.com/doc/refman/5.0/en/data-types.html>.
857  
858 L<Form::Sensible|Form::Sensible>,
859 L<Form::Sensible::Reflector|Form::Sensible::Reflector>,
860 L<Form::Sensible::Reflector::DBIC|Form::Sensible::Reflector::DBIC>,
861 L<Form::Sensible::Field|Form::Sensible::Field>.
862  
863 =head1 AUTHOR AND COPYRIGHT
864  
865 Copyright (C) Lee Goddard, 2010-2011. All Rights Reserved.
866  
867 Made available under the same terms as Perl.
868
869 =cut
870  
871 package Form::Sensible::Reflector::MySQL::I18N::enGB;
872  
873 =head1 NAME
874  
875 Form::Sensible::Reflector::MySQL::I18N::enGB - error messages
876  
877 =head1 DESCRIPTION
878  
879 This namesapce provides the default error messages for form
880 validation as described in L<Form::Sensible::Reflector::MySQL/INTERNATIONALISATION>.
881  
882 =cut
883  
884 11 ▶use base 'Exporter';
Subroutine BEGIN: called CC=1 SCAR=0.0
885  
886 11 our @EXPORT = qw( $I18N );
887  
888 11 ▶use constant {
Subroutine BEGIN: called CC=1 SCAR=0.0
889 11 NAN => '_FIELDNAME_ is not a valid number',
890 NOT_INT => '_FIELDNAME_ is not an integer',
891 11 };
892  
893 11 our $I18N = {
894
895 # Unsigned big integer
896 ubigint => {
897 nan => '_FIELDNAME_ is an invalid unsigned big integer',
898 not_int => NOT_INT,
899 too_high => '_FIELDNAME_ is higher than the maximum allowed value of 18446744073709551615',
900 too_low => '_FIELDNAME_ is lower than the maximum allowed value of 0',
901 },
902
903 # Signed big integer
904 sbigint => {
905 nan => '_FIELDNAME_ is an invalid signed big integer',
906 not_int => NOT_INT,
907 too_high => '_FIELDNAME_ is higher than the maximum allowed value of 9223372036854775807',
908 too_low => '_FIELDNAME_ is lower than the maximum allowed value of -9223372036854775808',
909 },
910
911 # Double/real
912 double => {
913 nan => NAN,
914 oob => '_FIELDNAME_ is out of bounds. Ranges are -1.7976931348623157E+308 to -2.2250738585072014E-308, 0 and 2.2250738585072014E-308 to 1.7976931348623157E+308',
915 },
916
917 # Float/double precision
918 float => {
919 nan => NAN,
920 oob => '_FIELDNAME is out of bounds. Ranges are –3.402823466E+38 to –1.175494351E-38, 0 and 1.175494351E-38 to 3.402823466E+38',
921 invalid => '_FIELDNAME_ is not a valid number format - digit length should not exceed ',
922 },
923  
924 # Decimal/numeric
925 decimal => {
926 nan => NAN,
927 too_long => '_FIELDNAME_ has too many digits in total: the maximum is ',
928 post_point => '_FIELDNAME_ has too many digits after the decimal point: the maximum is ',
929 },
930
931 bits => {
932 invalid => '_FIELDNAME_ must be a binary number with a maximum bit-length of ',
933 },
934
935 bit1 => {
936 oob => '_FIELDNAME_ must be \'on\' (1) or \'off\' (0)',
937 },
938
939 # varbinary/binary
940 binary => {
941 too_long => '_FIELDNAME_ should have no more bytes than ',
942 },
943  
944 tinyblob => {
945 too_long => '_FIELDNAME_ is longer than the maximum allowed length of 255 bytes',
946 },
947  
948 blob => {
949 too_long => '_FIELDNAME_ is longer than the maximum allowed length of 65535 bytes',
950 },
951
952 mediumblob => {
953 too_long => '_FIELDNAME_ is longer than the maximum allowed length of 16777215 bytes',
954 },
955
956 longblob => {
957 too_long => '_FIELDNAME_ is longer than the maximum allowed length of 4294967295 bytes',
958 },
959
960 datetime => {
961 year_length => '_FIELDNAME_ must have a four-digit year',
962 year_oob => '_FIELDNAME_ must have a year from 1001 to 9999',
963 parser_error_prefix => '',
964 },
965
966 timestamp => {
967 year_length => '_FIELDNAME_ must have a four-digit year',
968 year_oob => '_FIELDNAME_ must have a year from 1001 to 9999',
969 parser_error_prefix => '',
970 },
971
972 date => {
973 year_length => '_FIELDNAME_ must have a four-digit year',
974 year_oob => '_FIELDNAME_ must have a year from 1001 to 9999',
975 parser_error_prefix => '',
976 },
977  
978 time => {
979 invalid => '_FIELDNAME_ is not a valid time format',
980 hours => 'Hours in _FIELDNAME_ are out of range',
981 minutes => 'Minutes in _FIELDNAME_ are out of range',
982 seconds => 'Seconds in _FIELDNAME_ are out of range',
983 },
984  
985 # year(4)
986 year4 => {
987 oob => '_FIELDNAME_ must be a year between 1901 and 2155',
988 },
989 year => {
990 oob => '_FIELDNAME_ must be a year between 00 and 99',
991 },
992
993 };
994  
995 11 1;
996  
997 =head1 AUTHOR AND COPYRIGHT
998  
999 Copyright (C) Lee Goddard, 2010-2011. All Rights Reserved.
1000  
1001 Made available under the same terms as Perl.
1002  
↑ Summary