Meta/Class/Schema.pm

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