/usr/share/perl5/MongoDBx/Class/EmbeddedDocument.pm is in libmongodbx-class-perl 1.030002-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 | package MongoDBx::Class::EmbeddedDocument;
# ABSTRACT: A MongoDBx::Class embedded (sub-)document role
our $VERSION = "1.030002";
$VERSION = eval $VERSION;
use Moose::Role;
use namespace::autoclean;
=head1 NAME
MongoDBx::Class::EmbeddedDocument - A MongoDBx::Class embedded (sub-)document role
=head1 VERSION
version 1.030002
=head1 SYNOPSIS
# create an embedded document class
package MyApp::Schema::PersonName;
use MongoDBx::Class::Moose; # use this instead of Moose
use namespace::autoclean;
with 'MongoDBx::Class::EmbeddedDocument';
has 'first_name' => (is => 'ro', isa => 'Str', required => 1, writer => 'set_first_name');
has 'middle_name' => (is => 'ro', isa => 'Str', predicate => 'has_middle_name', writer => 'set_middle_name');
has 'last_name' => (is => 'ro', isa => 'Str', required => 1, writer => 'set_last_name');
sub name {
my $self = shift;
my $name = $self->first_name;
$name .= ' '.$self->middle_name.' ' if $self->has_middle_name;
$name .= $self->last_name;
return $name;
}
__PACKAGE__->meta->make_immutable;
=head1 DESCRIPTION
MongoDBx::Class::EmbeddedDocument is a L<Moose role|Moose::Role> meant
to be consumed by document classes representing embedded documents. These
are documents that are entirely contained within parent MongoDB documents.
The role provides expanded embedded documents with some common attributes
and useful methods.
=head1 ATTRIBUTES
=head2 _collection
The L<MongoDBx::Class::Collection> object representing the MongoDB collection
in which this embedded document is stored (more correctly, the collection
in which the L<MongoDBx::Class::Document> holding this embedded document
is stored). This is a required attribute.
=cut
has '_collection' => (is => 'ro', isa => 'MongoDBx::Class::Collection', required => 1);
=head2 _class
A string. The name of the document class of this embedded document.
A required attribute.
=cut
has '_class' => (is => 'ro', isa => 'Str', required => 1);
=head1 METHODS
The following methods are provided:
=head2 as_hashref()
Returns the embedded document as a hash reference, without the _collection
and _class attributes (if they exist).
=cut
sub as_hashref {
my ($self, $hash) = (shift, {});
foreach my $ha (keys %$self) {
next if $ha eq '_collection' || $ha eq '_class';
$hash->{$ha} = $self->{$ha};
}
return $hash;
}
=head1 INTERNAL METHODS
=head2 _database()
Convenience shortcut for running C<< $embd_doc->_collection->_database >>.
=cut
sub _database {
shift->_collection->_database;
}
=head2 _attributes()
Returns a list of names of all attributes the embedded document object has,
minus '_collection' and '_class', sorted alphabetically.
=cut
sub _attributes {
my @names;
foreach (shift->meta->get_all_attributes) {
next if $_->name =~ m/^_(class|collection)$/;
if ($_->{isa} =~ m/MongoDBx::Class::CoercedReference/ || ($_->documentation && $_->documentation eq 'MongoDBx::Class::EmbeddedDocument')) {
my $name = $_->name;
$name =~ s/^_//;
push(@names, $name);
} else {
push(@names, $_->name);
}
}
return sort @names;
}
=head1 AUTHOR
Ido Perlmuter, C<< <ido at ido50.net> >>
=head1 BUGS
Please report any bugs or feature requests to C<bug-mongodbx-class at rt.cpan.org>, or through
the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=MongoDBx-Class>. I will be notified, and then you'll
automatically be notified of progress on your bug as I make changes.
=head1 SUPPORT
You can find documentation for this module with the perldoc command.
perldoc MongoDBx::Class::EmbeddedDocument
You can also look for information at:
=over 4
=item * RT: CPAN's request tracker
L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=MongoDBx::Class>
=item * AnnoCPAN: Annotated CPAN documentation
L<http://annocpan.org/dist/MongoDBx::Class>
=item * CPAN Ratings
L<http://cpanratings.perl.org/d/MongoDBx::Class>
=item * Search CPAN
L<http://search.cpan.org/dist/MongoDBx::Class/>
=back
=head1 SEE ALSO
L<MongoDBx::Class::Moose>, L<MongoDBx::Class::Document>.
=head1 LICENSE AND COPYRIGHT
Copyright 2010-2014 Ido Perlmuter.
This program is free software; you can redistribute it and/or modify it
under the terms of either: the GNU General Public License as published
by the Free Software Foundation; or the Artistic License.
See http://dev.perl.org/licenses/ for more information.
=cut
1;
|