line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Fey::Meta::Class::Schema; |
2
|
|
|
|
|
|
|
|
3
|
10
|
|
|
10
|
|
55
|
use strict; |
|
10
|
|
|
|
|
14
|
|
|
10
|
|
|
|
|
396
|
|
4
|
10
|
|
|
10
|
|
55
|
use warnings; |
|
10
|
|
|
|
|
14
|
|
|
10
|
|
|
|
|
340
|
|
5
|
10
|
|
|
10
|
|
52
|
use namespace::autoclean; |
|
10
|
|
|
|
|
15
|
|
|
10
|
|
|
|
|
88
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our $VERSION = '0.47'; |
8
|
|
|
|
|
|
|
|
9
|
10
|
|
|
10
|
|
6935
|
use Fey::DBIManager; |
|
10
|
|
|
|
|
2619574
|
|
|
10
|
|
|
|
|
510
|
|
10
|
10
|
|
|
10
|
|
128
|
use Fey::Exceptions qw( param_error ); |
|
10
|
|
|
|
|
18
|
|
|
10
|
|
|
|
|
829
|
|
11
|
10
|
|
|
10
|
|
2153
|
use Fey::ORM::Types qw( ClassName HashRef ); |
|
10
|
|
|
|
|
22
|
|
|
10
|
|
|
|
|
100
|
|
12
|
|
|
|
|
|
|
|
13
|
10
|
|
|
10
|
|
53021
|
use Moose; |
|
10
|
|
|
|
|
20
|
|
|
10
|
|
|
|
|
88
|
|
14
|
10
|
|
|
10
|
|
200806
|
use MooseX::ClassAttribute; |
|
10
|
|
|
|
|
809383
|
|
|
10
|
|
|
|
|
52
|
|
15
|
10
|
|
|
10
|
|
676130
|
use MooseX::Params::Validate qw( pos_validated_list ); |
|
10
|
|
|
|
|
20
|
|
|
10
|
|
|
|
|
94
|
|
16
|
10
|
|
|
10
|
|
1955
|
use MooseX::SemiAffordanceAccessor; |
|
10
|
|
|
|
|
17
|
|
|
10
|
|
|
|
|
85
|
|
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
extends 'Moose::Meta::Class'; |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
class_has '_SchemaClassMap' => ( |
21
|
|
|
|
|
|
|
traits => ['Hash'], |
22
|
|
|
|
|
|
|
is => 'ro', |
23
|
|
|
|
|
|
|
isa => HashRef ['Fey::Schema'], |
24
|
|
|
|
|
|
|
default => sub { {} }, |
25
|
|
|
|
|
|
|
lazy => 1, |
26
|
|
|
|
|
|
|
handles => { |
27
|
|
|
|
|
|
|
SchemaForClass => 'get', |
28
|
|
|
|
|
|
|
_SetSchemaForClass => 'set', |
29
|
|
|
|
|
|
|
_ClassHasSchema => 'exists', |
30
|
|
|
|
|
|
|
}, |
31
|
|
|
|
|
|
|
); |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
has 'schema' => ( |
34
|
|
|
|
|
|
|
is => 'rw', |
35
|
|
|
|
|
|
|
isa => 'Fey::Schema', |
36
|
|
|
|
|
|
|
writer => '_set_schema', |
37
|
|
|
|
|
|
|
predicate => '_has_schema', |
38
|
|
|
|
|
|
|
); |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
has 'dbi_manager' => ( |
41
|
|
|
|
|
|
|
is => 'rw', |
42
|
|
|
|
|
|
|
isa => 'Fey::DBIManager', |
43
|
|
|
|
|
|
|
lazy => 1, |
44
|
|
|
|
|
|
|
default => sub { Fey::DBIManager->new() }, |
45
|
|
|
|
|
|
|
); |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
has 'sql_factory_class' => ( |
48
|
|
|
|
|
|
|
is => 'rw', |
49
|
|
|
|
|
|
|
isa => ClassName, |
50
|
|
|
|
|
|
|
lazy => 1, |
51
|
|
|
|
|
|
|
default => 'Fey::SQL', |
52
|
|
|
|
|
|
|
); |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
sub ClassForSchema { |
55
|
37
|
|
|
37
|
1
|
277
|
my $class = shift; |
56
|
37
|
|
|
|
|
214
|
my ($schema) = pos_validated_list( \@_, { isa => 'Fey::Schema' } ); |
57
|
|
|
|
|
|
|
|
58
|
37
|
|
|
|
|
8129
|
my $map = $class->_SchemaClassMap(); |
59
|
|
|
|
|
|
|
|
60
|
37
|
|
|
|
|
61
|
for my $class_name ( keys %{$map} ) { |
|
37
|
|
|
|
|
130
|
|
61
|
|
|
|
|
|
|
return $class_name |
62
|
27
|
100
|
|
|
|
751
|
if $map->{$class_name}->name() eq $schema->name(); |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
11
|
|
|
|
|
57
|
return; |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
## no critic (Subroutines::ProhibitUnusedPrivateSubroutines) |
69
|
|
|
|
|
|
|
sub _associate_schema { |
70
|
11
|
|
|
11
|
|
29
|
my $self = shift; |
71
|
11
|
|
|
|
|
19
|
my $schema = shift; |
72
|
|
|
|
|
|
|
|
73
|
11
|
|
|
|
|
106
|
my $caller = $self->name(); |
74
|
|
|
|
|
|
|
|
75
|
11
|
50
|
|
|
|
474
|
param_error 'Cannot call has_schema() more than once per class' |
76
|
|
|
|
|
|
|
if $self->_has_schema(); |
77
|
|
|
|
|
|
|
|
78
|
11
|
100
|
|
|
|
67
|
param_error 'Cannot associate the same schema with multiple classes' |
79
|
|
|
|
|
|
|
if __PACKAGE__->ClassForSchema($schema); |
80
|
|
|
|
|
|
|
|
81
|
10
|
|
|
|
|
473
|
__PACKAGE__->_SetSchemaForClass( $self->name() => $schema ); |
82
|
|
|
|
|
|
|
|
83
|
10
|
|
|
|
|
501
|
$self->_set_schema($schema); |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
## use critic |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
__PACKAGE__->meta()->make_immutable(); |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
1; |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
# ABSTRACT: A metaclass for schema classes |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
__END__ |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
=pod |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
=head1 NAME |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
Fey::Meta::Class::Schema - A metaclass for schema classes |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
=head1 VERSION |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
version 0.47 |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
=head1 SYNOPSIS |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
package MyApp::Schema; |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
use Fey::ORM::Schema; |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
print __PACKAGE__->meta()->ClassForSchema($schema); |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
=head1 DESCRIPTION |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
This is the metaclass for schema classes. When you use |
116
|
|
|
|
|
|
|
L<Fey::ORM::Schema> in your class, it uses this class to do all the |
117
|
|
|
|
|
|
|
heavy lifting. |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
=head1 METHODS |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
This class provides the following methods: |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
=head2 Fey::Meta::Class::Schema->ClassForSchema($schema) |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
Given a L<Fey::Schema> object, this method returns the name of the |
126
|
|
|
|
|
|
|
class which "has" that schema, if any. |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
=head2 Fey::Meta::Class::Schema->SchemaForClass($class) |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
Given a class, this method returns the L<Fey::Schema> object |
131
|
|
|
|
|
|
|
associated with that class, if any. |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
=head2 $meta->table() |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
Returns the L<Fey::Schema> for the metaclass's class. |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
=head1 AUTHOR |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
Dave Rolsky <autarch@urth.org> |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
This software is copyright (c) 2011 - 2015 by Dave Rolsky. |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
146
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
=cut |