File Coverage

blib/lib/Fey/Meta/Role/Relationship.pm
Criterion Covered Total %
statement 17 17 100.0
branch n/a
condition n/a
subroutine 6 6 100.0
pod n/a
total 23 23 100.0


line stmt bran cond sub pod time code
1             package Fey::Meta::Role::Relationship;
2              
3 10     10   6490 use strict;
  10         14  
  10         310  
4 10     10   42 use warnings;
  10         17  
  10         281  
5 10     10   43 use namespace::autoclean;
  10         18  
  10         66  
6              
7             our $VERSION = '0.47';
8              
9 10     10   875 use Fey::ORM::Types qw( Bool CodeRef Str TableWithSchema );
  10         29  
  10         89  
10              
11 10     10   71188 use Moose::Role;
  10         18  
  10         99  
12              
13             has associated_class => (
14             is => 'rw',
15             isa => 'Fey::Meta::Class::Table',
16             writer => '_set_associated_class',
17             clearer => '_clear_associated_class',
18             weak_ref => 1,
19             init_arg => undef,
20             );
21              
22             has name => (
23             is => 'ro',
24             isa => Str,
25             lazy => 1,
26             builder => '_build_name',
27             );
28              
29             has namer => (
30             is => 'ro',
31             isa => CodeRef,
32             required => 1,
33             );
34              
35             has table => (
36             is => 'ro',
37             isa => TableWithSchema,
38             required => 1,
39             );
40              
41             has foreign_table => (
42             is => 'ro',
43             isa => TableWithSchema,
44             required => 1,
45             );
46              
47             has is_cached => (
48             is => 'ro',
49             isa => Bool,
50             lazy => 1,
51             builder => '_build_is_cached',
52             );
53              
54             sub _build_name {
55 4     4   9 my $self = shift;
56              
57 4         156 return $self->namer()->( $self->foreign_table(), $self );
58             }
59              
60             1;
61              
62             # ABSTRACT: A shared role for all foreign HasX metaclasses
63              
64             __END__
65              
66             =pod
67              
68             =head1 NAME
69              
70             Fey::Meta::Role::Relationship - A shared role for all foreign HasX metaclasses
71              
72             =head1 VERSION
73              
74             version 0.47
75              
76             =head1 DESCRIPTION
77              
78             This role provides shared functionality for has-one and has-many
79             metaclasses. See the relevant classes for documentation.
80              
81             =head1 CONSTRUCTOR OPTIONS
82              
83             This role adds the following constructor options:
84              
85             =over 4
86              
87             =item * name
88              
89             The name of the relationship. This will be used as the name for any
90             attribute or method created by this metaclass.
91              
92             This defaults to C<< lc $self->foreign_table()->name() >>.
93              
94             =item * table
95              
96             The (source) table of the foreign key.
97              
98             =item * foreign_table
99              
100             The foreign table for the foreign key
101              
102             =item * is_cached
103              
104             Determines whether the relationship's value is cached. This is
105             implemented in different ways for has-one vs has-many relationships.
106              
107             =back
108              
109             =head1 AUTHOR
110              
111             Dave Rolsky <autarch@urth.org>
112              
113             =head1 COPYRIGHT AND LICENSE
114              
115             This software is copyright (c) 2011 - 2015 by Dave Rolsky.
116              
117             This is free software; you can redistribute it and/or modify it under
118             the same terms as the Perl 5 programming language system itself.
119              
120             =cut