| 1 | package DBIx::MoCo::Schema; | ||||||||||||||||||||||||||||
| 2 | 12 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | 12 | ▶ | use Carp; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | 15 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 6 | 15 | my $class = shift; | |||||||||||||||||||||||||||
| 7 | 15 | ▶ | my $klass = shift or return; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 8 | 15 | my $self = { | |||||||||||||||||||||||||||
| 9 | class => $klass, | ||||||||||||||||||||||||||||
| 10 | primary_keys => undef, | ||||||||||||||||||||||||||||
| 11 | uniquie_keys => undef, | ||||||||||||||||||||||||||||
| 12 | retrieve_keys => undef, | ||||||||||||||||||||||||||||
| 13 | utf8_columns => undef, | ||||||||||||||||||||||||||||
| 14 | columns => undef, | ||||||||||||||||||||||||||||
| 15 | }; | ||||||||||||||||||||||||||||
| 16 | 15 | bless $self, $class; | |||||||||||||||||||||||||||
| 17 | } | ||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | 203 | ▶ | sub primary_keys { | ||||||||||||||||||||||||||
|
Subroutine
primary_keys: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 20 | 203 | my $self = shift; | |||||||||||||||||||||||||||
| 21 | 203 | ▶ | unless ($self->{primary_keys}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 22 | 6 | my $class = $self->{class}; | |||||||||||||||||||||||||||
| 23 | 6 | $self->{primary_keys} = $class->db->primary_keys($class->table); | |||||||||||||||||||||||||||
| 24 | } | ||||||||||||||||||||||||||||
| 25 | 203 | $self->{primary_keys}; | |||||||||||||||||||||||||||
| 26 | } | ||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | 14 | ▶ | sub unique_keys { | ||||||||||||||||||||||||||
|
Subroutine
unique_keys: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 29 | 14 | my $self = shift; | |||||||||||||||||||||||||||
| 30 | 14 | ▶ | unless ($self->{unique_keys}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 31 | 2 | my $class = $self->{class}; | |||||||||||||||||||||||||||
| 32 | 2 | $self->{unique_keys} = $class->db->unique_keys($class->table); | |||||||||||||||||||||||||||
| 33 | } | ||||||||||||||||||||||||||||
| 34 | 14 | $self->{unique_keys}; | |||||||||||||||||||||||||||
| 35 | } | ||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | 112 | ▶ | sub retrieve_keys { | ||||||||||||||||||||||||||
|
Subroutine
retrieve_keys: called CC=2 SCAR=7.1
Pod
undocumented
| |||||||||||||||||||||||||||||
| 38 | 112 | my $self = shift; | |||||||||||||||||||||||||||
| 39 | 112 | ▶ | $self->{retrieve_keys} = $_[0] if $_[0]; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 40 | 112 | return $self->{retrieve_keys}; | |||||||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | 5 | ▶ | sub utf8_columns { | ||||||||||||||||||||||||||
|
Subroutine
utf8_columns: called CC=5 SCAR=16.3
Pod
undocumented
| |||||||||||||||||||||||||||||
| 44 | 5 | my $self = shift; | |||||||||||||||||||||||||||
| 45 | 5 | ▶ | if (@_) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 46 | 1 | ▶ | my $cols = (ref $_[0] and ref $_[0] eq 'ARRAY') ? $_[0] : [ @_ ]; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
ref $_[0] and ref $_[0] eq "ARRAY"
MC/DC0%0/2
ref $_[0] and ref $_[0] eq "ARRAY"
ref $_[0]
ref $_[0] eq "ARRAY"
Truth table33%1/3
A and B
A= ref $_[0]B= ref $_[0] eq "ARRAY"
| |||||||||||||||||||||||||||||
| 47 | 1 | $self->{utf8_columns} = $cols; | |||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | 1 | my $class = $self->{class}; | |||||||||||||||||||||||||||
| 50 | 12 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 51 | 1 | for my $col (@$cols) { | |||||||||||||||||||||||||||
| 52 | 2 | my $method = $class . '::' . $col; | |||||||||||||||||||||||||||
| 53 | 2 | *$method = $class->_column_as_handler($col, 'utf8'); | |||||||||||||||||||||||||||
| 54 | # warn $method; | ||||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||
| 57 | 5 | return $self->{utf8_columns}; | |||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | 149 | ▶ | sub columns { | ||||||||||||||||||||||||||
|
Subroutine
columns: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 61 | 149 | my $self = shift; | |||||||||||||||||||||||||||
| 62 | 149 | ▶ | unless ($self->{columns}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 63 | 13 | my $class = $self->{class}; | |||||||||||||||||||||||||||
| 64 | 13 | $self->{columns} = $class->db->columns($class->table); | |||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||
| 66 | 149 | $self->{columns}; | |||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | 4 | ▶ | sub param { | ||||||||||||||||||||||||||
|
Subroutine
param: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 70 | 4 | my $self = shift; | |||||||||||||||||||||||||||
| 71 | 4 | ▶ | return $self->{$_[0]} if not exists $_[1]; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 72 | 2 | ▶ | @_ % 2 and croak | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 73 | sprintf "%s : You gave me an odd number of parameters to param()"; | ||||||||||||||||||||||||||||
| 74 | 2 | my %args = @_; | |||||||||||||||||||||||||||
| 75 | 2 | $self->{$_} = $args{$_} for keys %args; | |||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | 12 | 1; | |||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | =head1 NAME | ||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||
| 82 | DBIx::MoCo::Schema - Schema class for DBIx::MoCo classes | ||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||
| 86 | my $schema = DBIx::MoCo::Schema->new('MyMoCoClass'); # make an instance | ||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||
| 88 | my $schema = MyMoCoClass->schema; # MyMoCoClass isa DBIx::MoCo | ||||||||||||||||||||||||||||
| 89 | $schema->primary_keys; # same as MyMoCoClass->primary_keys | ||||||||||||||||||||||||||||
| 90 | $schema->uniquie_keys; # same as MyMoCoClass->uniquie_keys | ||||||||||||||||||||||||||||
| 91 | $schema->columns; # same as MyMoCoClass->columns | ||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||
| 93 | # you can set any parameters using param | ||||||||||||||||||||||||||||
| 94 | $schema->param(validation => { | ||||||||||||||||||||||||||||
| 95 | name => ['NOT_BLANK', 'ASCII', ['LENGTH', 2, 5]], | ||||||||||||||||||||||||||||
| 96 | # for example, FormValidator::Simple style definitions | ||||||||||||||||||||||||||||
| 97 | }); | ||||||||||||||||||||||||||||
| 98 | $schema->param('validation'); # returns validation definitions | ||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||
| 100 | =head1 SEE ALSO | ||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||
| 102 | L<DBIx::MoCo>, L<FormValidator::Simple> | ||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||
| 104 | =head1 AUTHOR | ||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||
| 106 | Junya Kondo, E<lt>jkondo@hatena.comE<gt> | ||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||
| 108 | =head1 COPYRIGHT AND LICENSE | ||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||
| 110 | Copyright (C) Hatena Inc. All Rights Reserved. | ||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||
| 112 | This library is free software; you may redistribute it and/or modify | ||||||||||||||||||||||||||||
| 113 | it under the same terms as Perl itself. | ||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||
| 115 | =cut | ||||||||||||||||||||||||||||