| 1 | |||
| 2 | =head1 Name | ||
| 3 | |||
| 4 | QBit::Application::Model::DB::Field | ||
| 5 | |||
| 6 | =head1 Description | ||
| 7 | |||
| 8 | Base class for DB fields. | ||
| 9 | |||
| 10 | =cut | ||
| 11 | |||
| 12 | package QBit::Application::Model::DB::Field; | ||
| 13 | $QBit::Application::Model::DB::Field::VERSION = '0.030'; | ||
| 14 | use qbit; | ||
| 15 | |||
| 16 | use base qw(QBit::Application::Model::DB::Class); | ||
| 17 | |||
| 18 | =head1 RO accessors | ||
| 19 | |||
| 20 | =over | ||
| 21 | |||
| 22 | =item * | ||
| 23 | |||
| 24 | B<name> | ||
| 25 | |||
| 26 | =item * | ||
| 27 | |||
| 28 | B<type> | ||
| 29 | |||
| 30 | =item * | ||
| 31 | |||
| 32 | B<table> | ||
| 33 | |||
| 34 | =back | ||
| 35 | |||
| 36 | =cut | ||
| 37 | |||
| 38 | __PACKAGE__->mk_ro_accessors( | ||
| 39 | qw( | ||
| 40 | name | ||
| 41 | type | ||
| 42 | table | ||
| 43 | ) | ||
| 44 | ); | ||
| 45 | |||
| 46 | =head1 Package methods | ||
| 47 | |||
| 48 | =head2 init | ||
| 49 | |||
| 50 | =cut | ||
| 51 | |||
| 52 | sub init { | ||
| 53 | my ($self) = @_; | ||
| 54 | |||
| 55 | $self->SUPER::init(); | ||
| 56 | |||
| 57 | weaken($self->{'table'}); | ||
| 58 | |||
| 59 | $self->init_check(); | ||
| 60 | } | ||
| 61 | |||
| 62 | =head2 init_check | ||
| 63 | |||
| 64 | =cut | ||
| 65 | |||
| 66 | sub init_check { | ||
| 67 | my ($self) = @_; | ||
| 68 | |||
| 69 | my @mis_params = grep {!exists($self->{$_})} qw(name type); | ||
| 70 | |||
| 71 | throw gettext('Need required parameter(s): %s (Table "%s")', join(', ', @mis_params), $self->table->name) | ||
| 72 | if @mis_params; | ||
| 73 | } | ||
| 74 | |||
| 75 | =head1 Abstract methods | ||
| 76 | |||
| 77 | =over | ||
| 78 | |||
| 79 | =item * | ||
| 80 | |||
| 81 | B<create_sql> | ||
| 82 | |||
| 83 | =back | ||
| 84 | |||
| 85 | =cut | ||
| 86 | |||
| 87 | sub create_sql {throw 'Abstract method'} | ||
| 88 | |||
| 89 | TRUE; | ||
| 90 | |||
| 91 | =pod | ||
| 92 | |||
| 93 | For more information see code and test. | ||
| 94 | |||
| 95 | =cut |