| 1 | package Class::DBI::FormBuilder::Meta::Column; | ||||||||||||||||||||
| 2 | 32 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 3 | 32 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 4 | |||||||||||||||||||||
| 5 | 32 | ▶ | use base qw( Class::Accessor Class::Data::Inheritable ); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 6 | |||||||||||||||||||||
| 7 | BEGIN | ||||||||||||||||||||
| 8 | 32 | ▶ | { | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 9 | # this is the list of column meta that we are interested in - add more items if wanted | ||||||||||||||||||||
| 10 | 32 | __PACKAGE__->mk_classdata( 'column_attributes', [ qw( column_def column_size decimal_digits | |||||||||||||||||||
| 11 | nullable is_nullable | ||||||||||||||||||||
| 12 | ordinal_position type_name foo | ||||||||||||||||||||
| 13 | |||||||||||||||||||||
| 14 | mysql_values mysql_type_name ) ] ); | ||||||||||||||||||||
| 15 | |||||||||||||||||||||
| 16 | 32 | __PACKAGE__->mk_accessors( qw( name table column_attributes ), @{ __PACKAGE__->column_attributes } ); | |||||||||||||||||||
| 17 | |||||||||||||||||||||
| 18 | } | ||||||||||||||||||||
| 19 | |||||||||||||||||||||
| 20 | 32 | ▶ | use overload '""' => 'name'; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 21 | |||||||||||||||||||||
| 22 | 32 | *order = \&ordinal_position; | |||||||||||||||||||
| 23 | 32 | *digits = \&decimal_digits; | |||||||||||||||||||
| 24 | 32 | *size = \&column_size; | |||||||||||||||||||
| 25 | 32 | *default = \&column_def; | |||||||||||||||||||
| 26 | |||||||||||||||||||||
| 27 | =head1 NAME | ||||||||||||||||||||
| 28 | |||||||||||||||||||||
| 29 | Class::DBI::FormBuilder::Meta::Column | ||||||||||||||||||||
| 30 | |||||||||||||||||||||
| 31 | =head1 DESCRIPTION | ||||||||||||||||||||
| 32 | |||||||||||||||||||||
| 33 | Access to column metadata. | ||||||||||||||||||||
| 34 | |||||||||||||||||||||
| 35 | =head1 METHODS | ||||||||||||||||||||
| 36 | |||||||||||||||||||||
| 37 | =over 4 | ||||||||||||||||||||
| 38 | |||||||||||||||||||||
| 39 | =item new($table, $name, $meta) | ||||||||||||||||||||
| 40 | |||||||||||||||||||||
| 41 | Returns a new meta object for the column. | ||||||||||||||||||||
| 42 | |||||||||||||||||||||
| 43 | Stringifies to the column's C<name>. | ||||||||||||||||||||
| 44 | |||||||||||||||||||||
| 45 | =cut | ||||||||||||||||||||
| 46 | |||||||||||||||||||||
| 47 | sub new | ||||||||||||||||||||
| 48 | 0 | ▶ | { | ||||||||||||||||||
|
Subroutine
new: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||
| 49 | 0 | my ($proto, $table, $name, $meta) = @_; | |||||||||||||||||||
| 50 | |||||||||||||||||||||
| 51 | 0 | ▶ | my $self = bless { table => $table, # reference to table meta object | ||||||||||||||||||
|
Condition0%0/3
ref $proto || $proto
MC/DC0%0/2
ref $proto || $proto
ref $proto
$proto
Truth table0%0/3
A || B
A= ref $protoB= $proto
| |||||||||||||||||||||
| 52 | name => $name, | ||||||||||||||||||||
| 53 | %$meta, | ||||||||||||||||||||
| 54 | }, ref($proto) || $proto; | ||||||||||||||||||||
| 55 | |||||||||||||||||||||
| 56 | 0 | return $self; | |||||||||||||||||||
| 57 | } | ||||||||||||||||||||
| 58 | |||||||||||||||||||||
| 59 | =item table | ||||||||||||||||||||
| 60 | |||||||||||||||||||||
| 61 | Returns the L<Class::DBI::FormBuilder::Table> object associated with this column. | ||||||||||||||||||||
| 62 | |||||||||||||||||||||
| 63 | =back | ||||||||||||||||||||
| 64 | |||||||||||||||||||||
| 65 | =head2 Column attribute accessors | ||||||||||||||||||||
| 66 | |||||||||||||||||||||
| 67 | =over 4 | ||||||||||||||||||||
| 68 | |||||||||||||||||||||
| 69 | =item name | ||||||||||||||||||||
| 70 | |||||||||||||||||||||
| 71 | =item order | ||||||||||||||||||||
| 72 | |||||||||||||||||||||
| 73 | =item ordinal_position | ||||||||||||||||||||
| 74 | |||||||||||||||||||||
| 75 | Alias for C<order>. | ||||||||||||||||||||
| 76 | |||||||||||||||||||||
| 77 | =item digits | ||||||||||||||||||||
| 78 | |||||||||||||||||||||
| 79 | =item decimal_digits | ||||||||||||||||||||
| 80 | |||||||||||||||||||||
| 81 | Alias for C<digits>. | ||||||||||||||||||||
| 82 | |||||||||||||||||||||
| 83 | =item size | ||||||||||||||||||||
| 84 | |||||||||||||||||||||
| 85 | =item column_size | ||||||||||||||||||||
| 86 | |||||||||||||||||||||
| 87 | Alias for C<size>. | ||||||||||||||||||||
| 88 | |||||||||||||||||||||
| 89 | =item default | ||||||||||||||||||||
| 90 | |||||||||||||||||||||
| 91 | =item column_def | ||||||||||||||||||||
| 92 | |||||||||||||||||||||
| 93 | Alias for C<default>. | ||||||||||||||||||||
| 94 | |||||||||||||||||||||
| 95 | =item nullable | ||||||||||||||||||||
| 96 | |||||||||||||||||||||
| 97 | =item is_nullable | ||||||||||||||||||||
| 98 | |||||||||||||||||||||
| 99 | =item type | ||||||||||||||||||||
| 100 | |||||||||||||||||||||
| 101 | =item type_name | ||||||||||||||||||||
| 102 | |||||||||||||||||||||
| 103 | Alias for C<type>. | ||||||||||||||||||||
| 104 | |||||||||||||||||||||
| 105 | =item mysql_values | ||||||||||||||||||||
| 106 | |||||||||||||||||||||
| 107 | =item mysql_type_name | ||||||||||||||||||||
| 108 | |||||||||||||||||||||
| 109 | =cut | ||||||||||||||||||||
| 110 | |||||||||||||||||||||
| 111 | sub type | ||||||||||||||||||||
| 112 | 0 | ▶ | { | ||||||||||||||||||
|
Subroutine
type: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||
| 113 | 0 | my ( $self ) = @_; | |||||||||||||||||||
| 114 | |||||||||||||||||||||
| 115 | 0 | ▶ | my $type = $self->type_name || die "No type_name for $self"; | ||||||||||||||||||
|
Condition0%0/2
$self->type_name || die("No type_name for $self")
MC/DC0%0/1
$self->type_name || die("No type_name for $self")
$self->type_name
Truth table0%0/2
A
A= $self->type_name
| |||||||||||||||||||||
| 116 | |||||||||||||||||||||
| 117 | 0 | return lc $type; | |||||||||||||||||||
| 118 | } | ||||||||||||||||||||
| 119 | |||||||||||||||||||||
| 120 | =item options | ||||||||||||||||||||
| 121 | |||||||||||||||||||||
| 122 | Returns the possible values for an enumerated column, and whether the | ||||||||||||||||||||
| 123 | column can store multiple value. | ||||||||||||||||||||
| 124 | |||||||||||||||||||||
| 125 | Currently only implemented for MySQL C<enum> (multiple is false) and | ||||||||||||||||||||
| 126 | C<set> (multiple is true) column types, but should be easy to support | ||||||||||||||||||||
| 127 | other databases that offer similar column types. | ||||||||||||||||||||
| 128 | |||||||||||||||||||||
| 129 | =back | ||||||||||||||||||||
| 130 | |||||||||||||||||||||
| 131 | =cut | ||||||||||||||||||||
| 132 | |||||||||||||||||||||
| 133 | sub options | ||||||||||||||||||||
| 134 | 0 | ▶ | { | ||||||||||||||||||
|
Subroutine
options: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||
| 135 | 0 | my ($self) = @_; | |||||||||||||||||||
| 136 | |||||||||||||||||||||
| 137 | 0 | my $type = $self->type; | |||||||||||||||||||
| 138 | |||||||||||||||||||||
| 139 | 0 | ▶ | my $series = $type =~ /^(?:set|enum)$/o ? $self->mysql_values : []; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 140 | |||||||||||||||||||||
| 141 | 0 | ▶ | my $multiple = 1 if $type eq 'set'; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 142 | |||||||||||||||||||||
| 143 | 0 | return $series, $multiple; | |||||||||||||||||||
| 144 | } | ||||||||||||||||||||
| 145 | |||||||||||||||||||||
| 146 | |||||||||||||||||||||
| 147 | 32 | 1; | |||||||||||||||||||
| 148 | |||||||||||||||||||||
| 149 | |||||||||||||||||||||
| 150 | __END__ | ||||||||||||||||||||