| 1 | =head1 NAME | ||||||||||||||||||||
| 2 | |||||||||||||||||||||
| 3 | DBIx::SQLEngine::Schema::Column - Struct for database column info | ||||||||||||||||||||
| 4 | |||||||||||||||||||||
| 5 | =head1 SYNOPSIS | ||||||||||||||||||||
| 6 | |||||||||||||||||||||
| 7 | my $col = DBIx::SQLEngine::Schema::Column->new( | ||||||||||||||||||||
| 8 | name=>$colname, type=>$typename | ||||||||||||||||||||
| 9 | ); | ||||||||||||||||||||
| 10 | |||||||||||||||||||||
| 11 | print $col->name; | ||||||||||||||||||||
| 12 | |||||||||||||||||||||
| 13 | if ( $col->type eq 'text' ) { | ||||||||||||||||||||
| 14 | print "text, length " . $col->length; | ||||||||||||||||||||
| 15 | } else { | ||||||||||||||||||||
| 16 | print $col->type; | ||||||||||||||||||||
| 17 | } | ||||||||||||||||||||
| 18 | |||||||||||||||||||||
| 19 | =head1 DESCRIPTION | ||||||||||||||||||||
| 20 | |||||||||||||||||||||
| 21 | DBIx::SQLEngine::Schema::Column objects are very simple structures that hold information about columns in a database table or query result. | ||||||||||||||||||||
| 22 | |||||||||||||||||||||
| 23 | They are generally contained in a DBIx::SQLEngine::Schema::ColumnSet. | ||||||||||||||||||||
| 24 | |||||||||||||||||||||
| 25 | =cut | ||||||||||||||||||||
| 26 | |||||||||||||||||||||
| 27 | package DBIx::SQLEngine::Schema::Column; | ||||||||||||||||||||
| 28 | 6 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 29 | |||||||||||||||||||||
| 30 | ######################################################################## | ||||||||||||||||||||
| 31 | |||||||||||||||||||||
| 32 | =head1 REFERENCE | ||||||||||||||||||||
| 33 | |||||||||||||||||||||
| 34 | These methods are available for all types of column. | ||||||||||||||||||||
| 35 | |||||||||||||||||||||
| 36 | =head2 Constructor | ||||||||||||||||||||
| 37 | |||||||||||||||||||||
| 38 | =over 4 | ||||||||||||||||||||
| 39 | |||||||||||||||||||||
| 40 | =item new() | ||||||||||||||||||||
| 41 | |||||||||||||||||||||
| 42 | DBIx::SQLEngine::Schema::Column->new() : $column | ||||||||||||||||||||
| 43 | |||||||||||||||||||||
| 44 | Constructor. | ||||||||||||||||||||
| 45 | |||||||||||||||||||||
| 46 | =item new_from_hash | ||||||||||||||||||||
| 47 | |||||||||||||||||||||
| 48 | DBIx::SQLEngine::Schema::Column->new( %attrs ) : $column | ||||||||||||||||||||
| 49 | |||||||||||||||||||||
| 50 | Constructor. | ||||||||||||||||||||
| 51 | |||||||||||||||||||||
| 52 | =back | ||||||||||||||||||||
| 53 | |||||||||||||||||||||
| 54 | =head2 Accessors | ||||||||||||||||||||
| 55 | |||||||||||||||||||||
| 56 | =over 4 | ||||||||||||||||||||
| 57 | |||||||||||||||||||||
| 58 | =item type | ||||||||||||||||||||
| 59 | |||||||||||||||||||||
| 60 | Dynamically reblesses instances into different subclasses of DBIx::SQLEngine::Schema::Column. | ||||||||||||||||||||
| 61 | |||||||||||||||||||||
| 62 | =item name | ||||||||||||||||||||
| 63 | |||||||||||||||||||||
| 64 | $column->name() : $name | ||||||||||||||||||||
| 65 | $column->name( $name ) | ||||||||||||||||||||
| 66 | |||||||||||||||||||||
| 67 | Basic string accessor. | ||||||||||||||||||||
| 68 | |||||||||||||||||||||
| 69 | =item required | ||||||||||||||||||||
| 70 | |||||||||||||||||||||
| 71 | $column->required() : $flag | ||||||||||||||||||||
| 72 | $column->required( $flag ) | ||||||||||||||||||||
| 73 | |||||||||||||||||||||
| 74 | Basic boolean accessor. | ||||||||||||||||||||
| 75 | |||||||||||||||||||||
| 76 | =back | ||||||||||||||||||||
| 77 | |||||||||||||||||||||
| 78 | =cut | ||||||||||||||||||||
| 79 | |||||||||||||||||||||
| 80 | 6 | ▶ | use Class::MakeMethods::Template::Hash ( | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 81 | 6 | 'Template::Hash:new' => 'new', | |||||||||||||||||||
| 82 | # 'Template::ClassName:subclass_name' => 'type', | ||||||||||||||||||||
| 83 | string => 'name', | ||||||||||||||||||||
| 84 | boolean => 'required', | ||||||||||||||||||||
| 85 | 6 | ); | |||||||||||||||||||
| 86 | |||||||||||||||||||||
| 87 | 10 | ▶ | sub type { | ||||||||||||||||||
|
Subroutine
type: called CC=4 SCAR=16.0
Pod
documented
| |||||||||||||||||||||
| 88 | 10 | my $self = shift; | |||||||||||||||||||
| 89 | 10 | ▶ | if ( ! scalar @_ ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 90 | 0 | ▶ | if ( ref $self ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 91 | return $self->{type} | ||||||||||||||||||||
| 92 | 0 | } else { | |||||||||||||||||||
| 93 | 0 | Class::MakeMethods::Template::ClassName::_pack_subclass(__PACKAGE__,$self) | |||||||||||||||||||
| 94 | } | ||||||||||||||||||||
| 95 | } else { | ||||||||||||||||||||
| 96 | 10 | my $classname = shift(); | |||||||||||||||||||
| 97 | 10 | my $subclass = Class::MakeMethods::Template::ClassName::_unpack_subclass( | |||||||||||||||||||
| 98 | __PACKAGE__, $classname); | ||||||||||||||||||||
| 99 | 10 | my $class = Class::MakeMethods::Template::ClassName::_provide_class( | |||||||||||||||||||
| 100 | __PACKAGE__, $subclass ); | ||||||||||||||||||||
| 101 | 10 | ▶ | if ( ref $self ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 102 | 10 | $self->{type} = $classname; | |||||||||||||||||||
| 103 | 10 | bless $self, $class; | |||||||||||||||||||
| 104 | } | ||||||||||||||||||||
| 105 | 10 | return $class; | |||||||||||||||||||
| 106 | } | ||||||||||||||||||||
| 107 | } | ||||||||||||||||||||
| 108 | |||||||||||||||||||||
| 109 | 0 | ▶ | sub new_from_hash { | ||||||||||||||||||
|
Subroutine
new_from_hash: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||
| 110 | 0 | my $class = shift; | |||||||||||||||||||
| 111 | 0 | ▶ | my %hash = (scalar @_ == 1) ? %{ $_[0] } : @_; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 112 | 0 | my $self = DBIx::SQLEngine::Schema::Column->new( type => $hash{type}, ); | |||||||||||||||||||
| 113 | 0 | ▶ | foreach my $k ( grep { $_ ne 'type' and $self->can($_) } keys %hash ) { | ||||||||||||||||||
|
Condition0%0/3
$_ ne 'type' && $self->can($_)
MC/DC0%0/2
$_ ne 'type' && $self->can($_)
$_ ne 'type'
$self->can($_)
Truth table0%0/3
A && B
A= $_ ne 'type'B= $self->can($_)
| |||||||||||||||||||||
| 114 | 0 | $self->$k($hash{$k}); | |||||||||||||||||||
| 115 | } | ||||||||||||||||||||
| 116 | 0 | $self; | |||||||||||||||||||
| 117 | } | ||||||||||||||||||||
| 118 | |||||||||||||||||||||
| 119 | ######################################################################## | ||||||||||||||||||||
| 120 | |||||||||||||||||||||
| 121 | =head2 text Attributes | ||||||||||||||||||||
| 122 | |||||||||||||||||||||
| 123 | These methods are only available for columns of type text. | ||||||||||||||||||||
| 124 | |||||||||||||||||||||
| 125 | =over 4 | ||||||||||||||||||||
| 126 | |||||||||||||||||||||
| 127 | =item length - Template::Hash:number | ||||||||||||||||||||
| 128 | |||||||||||||||||||||
| 129 | =back | ||||||||||||||||||||
| 130 | |||||||||||||||||||||
| 131 | =cut | ||||||||||||||||||||
| 132 | |||||||||||||||||||||
| 133 | package DBIx::SQLEngine::Schema::Column::text; | ||||||||||||||||||||
| 134 | 6 | @DBIx::SQLEngine::Schema::Column::text::ISA = 'DBIx::SQLEngine::Schema::Column'; | |||||||||||||||||||
| 135 | |||||||||||||||||||||
| 136 | 6 | ▶ | use Class::MakeMethods::Template::Hash ( | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 137 | 6 | number => 'length', | |||||||||||||||||||
| 138 | 6 | ); | |||||||||||||||||||
| 139 | |||||||||||||||||||||
| 140 | ######################################################################## | ||||||||||||||||||||
| 141 | |||||||||||||||||||||
| 142 | =head1 SEE ALSO | ||||||||||||||||||||
| 143 | |||||||||||||||||||||
| 144 | See L<DBIx::SQLEngine> for the overall interface and developer documentation. | ||||||||||||||||||||
| 145 | |||||||||||||||||||||
| 146 | See L<DBIx::SQLEngine::Docs::ReadMe> for general information about | ||||||||||||||||||||
| 147 | this distribution, including installation and license information. | ||||||||||||||||||||
| 148 | |||||||||||||||||||||
| 149 | =cut | ||||||||||||||||||||
| 150 | |||||||||||||||||||||
| 151 | ######################################################################## | ||||||||||||||||||||
| 152 | |||||||||||||||||||||
| 153 | 6 | 1; | |||||||||||||||||||