| 1 | |||
| 2 | =head1 NAME | ||
| 3 | |||
| 4 | InterMine::Model::Collection - represents a collection in an InterMine class | ||
| 5 | |||
| 6 | =head1 SYNOPSIS | ||
| 7 | |||
| 8 | use InterMine::Model::Collection | ||
| 9 | ... | ||
| 10 | my $field = InterMine::Model::Collection->new(name => 'genes', | ||
| 11 | model => $model, | ||
| 12 | referenced_type_name => | ||
| 13 | $ref_type, | ||
| 14 | reverse_reference_name => | ||
| 15 | $reverse_reference); | ||
| 16 | ... | ||
| 17 | |||
| 18 | =head1 DESCRIPTION | ||
| 19 | |||
| 20 | Objects of this class describe the collections of a class | ||
| 21 | in an InterMine model. Collection objects are generally part of | ||
| 22 | ClassDescriptor objects. | ||
| 23 | |||
| 24 | |||
| 25 | =cut | ||
| 26 | package InterMine::Model::Collection; | ||
| 27 | |||
| 28 | use Moose; | ||
| 29 | extends 'InterMine::Model::Reference'; | ||
| 30 | |||
| 31 | =head1 CONSTANTS | ||
| 32 | |||
| 33 | =head2 TAG_NAME | ||
| 34 | |||
| 35 | the name for serialising references to xml | ||
| 36 | |||
| 37 | =cut | ||
| 38 | |||
| 39 | use constant TAG_NAME => "collection"; | ||
| 40 | |||
| 41 | override '_get_moose_type' => sub { | ||
| 42 | my $self = shift; | ||
| 43 | return 'ArrayOf' . super; | ||
| 44 | }; | ||
| 45 | |||
| 46 | override '_get_moose_options' => sub { | ||
| 47 | my $self = shift; | ||
| 48 | my @ops = super; | ||
| 49 | my $push_method = "add" . ucfirst($self->name); | ||
| 50 | my $get_method = "get" . ucfirst($self->name); | ||
| 51 | my $size_method = $self->name . "_count"; | ||
| 52 | my $empty_method = $self->name . "_is_empty"; | ||
| 53 | |||
| 54 | $push_method =~ s/s$//; | ||
| 55 | $get_method =~ s/s$//; | ||
| 56 | $get_method .= "ByIndex"; | ||
| 57 | my $handles = {}; | ||
| 58 | $handles->{$push_method} = "push"; | ||
| 59 | $handles->{$get_method} = "get"; | ||
| 60 | $handles->{$size_method} = "count"; | ||
| 61 | $handles->{$empty_method} = "is_empty"; | ||
| 62 | |||
| 63 | push @ops, ( | ||
| 64 | traits => ['Array'], | ||
| 65 | auto_deref => 1, | ||
| 66 | handles => $handles, | ||
| 67 | default => sub { [] }, | ||
| 68 | ); | ||
| 69 | return @ops; | ||
| 70 | }; | ||
| 71 | |||
| 72 | __PACKAGE__->meta->make_immutable; | ||
| 73 | no Moose; | ||
| 74 | 1; | ||
| 75 | |||
| 76 | __END__ | ||
| 77 | |||
| 78 | =head1 SEE ALSO | ||
| 79 | |||
| 80 | =over 4 | ||
| 81 | |||
| 82 | =item L<InterMine::Model::ClassDescriptor> | ||
| 83 | |||
| 84 | =item L<InterMine::Model::Reference> | ||
| 85 | |||
| 86 | =item L<InterMine::Model::Role::Field> | ||
| 87 | |||
| 88 | =item L<InterMine::Model::Role::Descriptor> | ||
| 89 | |||
| 90 | =back | ||
| 91 | |||
| 92 | =head1 AUTHOR | ||
| 93 | |||
| 94 | FlyMine C<< <support@flymine.org> >> | ||
| 95 | |||
| 96 | =head1 BUGS | ||
| 97 | |||
| 98 | Please report any bugs or feature requests to C<support@flymine.org>. | ||
| 99 | |||
| 100 | =head1 SUPPORT | ||
| 101 | |||
| 102 | You can find documentation for this module with the perldoc command. | ||
| 103 | |||
| 104 | perldoc InterMine::Model::Collection | ||
| 105 | |||
| 106 | You can also look for information at: | ||
| 107 | |||
| 108 | =over 4 | ||
| 109 | |||
| 110 | =item * FlyMine | ||
| 111 | |||
| 112 | L<http://www.flymine.org> | ||
| 113 | |||
| 114 | =back | ||
| 115 | |||
| 116 | =head1 COPYRIGHT & LICENSE | ||
| 117 | |||
| 118 | Copyright 2006,2007,2008,2009,2010,2011 FlyMine, all rights reserved. | ||
| 119 | |||
| 120 | This program is free software; you can redistribute it and/or modify it | ||
| 121 | under the same terms as Perl itself. |