| 1 | package Mandel::Relationship; | ||||||||||
| 2 | 4 | ▶ | use Mojo::Base -base; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 3 | 4 | ▶ | use Mojo::Loader 'load_class'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | |||||||||||
| 5 | 4 | has accessor => ''; | |||||||||
| 6 | 4 | has document_class => ''; | |||||||||
| 7 | 2 | ▶ | has foreign_field => sub { shift->document_class->model->name }; | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 8 | 4 | has related_class => ''; | |||||||||
| 9 | |||||||||||
| 10 | # is this a bad memory leak? $model => $rel_obj => $_related_model | ||||||||||
| 11 | # i don't think so, since the number of objects are constant | ||||||||||
| 12 | 2 | ▶ | has _related_model => sub { | ||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.0
| |||||||||||
| 13 | 2 | my $self = shift; | |||||||||
| 14 | 2 | my $e = load_class($self->related_class); | |||||||||
| 15 | 2 | ▶ | die $e if ref $e; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 16 | 2 | $self->related_class->model; | |||||||||
| 17 | 4 | }; | |||||||||
| 18 | |||||||||||
| 19 | 4 | 1; | |||||||||
| 20 | |||||||||||
| 21 | =encoding utf8 | ||||||||||
| 22 | |||||||||||
| 23 | =head1 NAME | ||||||||||
| 24 | |||||||||||
| 25 | Mandel::Relationship - Base class for relationships | ||||||||||
| 26 | |||||||||||
| 27 | =head1 DESCRIPTION | ||||||||||
| 28 | |||||||||||
| 29 | L<Mandel::Relationship> is the base class for the following classes: | ||||||||||
| 30 | |||||||||||
| 31 | =over 4 | ||||||||||
| 32 | |||||||||||
| 33 | =item * L<Mandel::Relationship::BelongsTo> | ||||||||||
| 34 | |||||||||||
| 35 | =item * L<Mandel::Relationship::HasMany> | ||||||||||
| 36 | |||||||||||
| 37 | =item * L<Mandel::Relationship::HasOne> | ||||||||||
| 38 | |||||||||||
| 39 | =back | ||||||||||
| 40 | |||||||||||
| 41 | =head1 ATTRIBUTES | ||||||||||
| 42 | |||||||||||
| 43 | =head2 accessor | ||||||||||
| 44 | |||||||||||
| 45 | Base name of accessor(s) created. | ||||||||||
| 46 | |||||||||||
| 47 | =head2 foreign_field | ||||||||||
| 48 | |||||||||||
| 49 | The name of the field in the foreign class which hold the "_id". | ||||||||||
| 50 | |||||||||||
| 51 | =head2 document_class | ||||||||||
| 52 | |||||||||||
| 53 | Holds the classname of the document class that holds all the accessors and | ||||||||||
| 54 | methods created. | ||||||||||
| 55 | |||||||||||
| 56 | =head2 related_class | ||||||||||
| 57 | |||||||||||
| 58 | Holds the related document class name. | ||||||||||
| 59 | |||||||||||
| 60 | =head1 SEE ALSO | ||||||||||
| 61 | |||||||||||
| 62 | L<Mojolicious>, L<Mango>, L<Mandel> | ||||||||||
| 63 | |||||||||||
| 64 | =head1 AUTHOR | ||||||||||
| 65 | |||||||||||
| 66 | Jan Henning Thorsen - C<jhthorsen@cpan.org> | ||||||||||
| 67 | |||||||||||
| 68 | =cut | ||||||||||