| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Mongol::Model; |
|
2
|
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
384498
|
use Moose; |
|
|
2
|
|
|
|
|
2
|
|
|
|
2
|
|
|
|
|
10
|
|
|
4
|
|
|
|
|
|
|
|
|
5
|
2
|
|
|
2
|
|
8835
|
use MooseX::Storage; |
|
|
2
|
|
|
|
|
47204
|
|
|
|
2
|
|
|
|
|
7
|
|
|
6
|
2
|
|
|
2
|
|
1151
|
use MooseX::Storage::Engine; |
|
|
2
|
|
|
|
|
43917
|
|
|
|
2
|
|
|
|
|
404
|
|
|
7
|
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
with Storage( base => 'SerializedClass' ); |
|
9
|
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
my @MAPPED_CLASSES = qw( |
|
11
|
|
|
|
|
|
|
MongoDB::OID |
|
12
|
|
|
|
|
|
|
MongoDB::DBRef |
|
13
|
|
|
|
|
|
|
MongoDB::BSON::Binary |
|
14
|
|
|
|
|
|
|
DateTime |
|
15
|
|
|
|
|
|
|
); |
|
16
|
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
MooseX::Storage::Engine->add_custom_type_handler( |
|
18
|
|
|
|
|
|
|
$_ => ( |
|
19
|
|
|
|
|
|
|
expand => sub { shift() }, |
|
20
|
|
|
|
|
|
|
collapse => sub { shift() }, |
|
21
|
|
|
|
|
|
|
) |
|
22
|
|
|
|
|
|
|
) foreach ( @MAPPED_CLASSES ); |
|
23
|
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
around 'pack' => sub { |
|
25
|
|
|
|
|
|
|
my $orig = shift(); |
|
26
|
|
|
|
|
|
|
my $self = shift(); |
|
27
|
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
my %args = @_; |
|
29
|
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
my $result = $self->$orig( %args ); |
|
31
|
|
|
|
|
|
|
delete( $result->{__CLASS__} ) |
|
32
|
|
|
|
|
|
|
if( $args{no_class} ); |
|
33
|
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
return $result; |
|
35
|
|
|
|
|
|
|
}; |
|
36
|
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
sub serialize { |
|
38
|
1
|
|
|
1
|
1
|
2
|
my $self = shift(); |
|
39
|
|
|
|
|
|
|
|
|
40
|
1
|
|
|
|
|
4
|
return $self->pack( no_class => 1 ); |
|
41
|
|
|
|
|
|
|
} |
|
42
|
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
__PACKAGE__->meta()->make_immutable(); |
|
44
|
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
1; |
|
46
|
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
__END__ |
|
48
|
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
=pod |
|
50
|
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
=head1 NAME |
|
52
|
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
Mongol::Model - Everything is a model |
|
54
|
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
56
|
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
package Models::Person { |
|
58
|
|
|
|
|
|
|
use Moose; |
|
59
|
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
extends 'Mongol::Model'; |
|
61
|
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
has 'first_name' => ( |
|
63
|
|
|
|
|
|
|
is => 'ro', |
|
64
|
|
|
|
|
|
|
isa => 'Str', |
|
65
|
|
|
|
|
|
|
required => 1, |
|
66
|
|
|
|
|
|
|
); |
|
67
|
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
has 'last_name' => ( |
|
69
|
|
|
|
|
|
|
is => 'ro', |
|
70
|
|
|
|
|
|
|
isa => 'Str', |
|
71
|
|
|
|
|
|
|
required => 1, |
|
72
|
|
|
|
|
|
|
); |
|
73
|
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
__PACKAGE__->meta()->make_immutable(); |
|
75
|
|
|
|
|
|
|
} |
|
76
|
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
package main { |
|
78
|
|
|
|
|
|
|
use strict; |
|
79
|
|
|
|
|
|
|
use warnings; |
|
80
|
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
use Model::Person; |
|
82
|
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
my $person => Model::Person->new( |
|
84
|
|
|
|
|
|
|
{ |
|
85
|
|
|
|
|
|
|
first_name => 'Peter', |
|
86
|
|
|
|
|
|
|
last_name => 'Parker', |
|
87
|
|
|
|
|
|
|
} |
|
88
|
|
|
|
|
|
|
); |
|
89
|
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
my $hashref = $person->pack(); |
|
91
|
|
|
|
|
|
|
my $clone = Model::Person->unpack( $hashref ); |
|
92
|
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
my $nice_hashref = $person->serialize(); |
|
94
|
|
|
|
|
|
|
} |
|
95
|
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
97
|
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
In Mongol there's no need to defined your model classes as document or subdocument |
|
99
|
|
|
|
|
|
|
it knows automatically to diferentiate between them. Everything should be a model, |
|
100
|
|
|
|
|
|
|
if you're planning to store that information in the database then make sure your |
|
101
|
|
|
|
|
|
|
class inherits from this package. Right now all it does it takes care of the data |
|
102
|
|
|
|
|
|
|
serialization for you and it makes sure that some of the datatypes are converted correctly. |
|
103
|
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
=head1 METHODS |
|
105
|
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
=head2 pack |
|
107
|
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
my $hashref = $model->pack(); |
|
109
|
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
Inherited from L<MooseX::Storage>. |
|
111
|
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
=head2 unpack |
|
113
|
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
my $model = Model::Class->unpack( $hashref ); |
|
115
|
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
Inherited from L<MooseX::Storage>. |
|
117
|
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
=head2 serialize |
|
119
|
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
my $hashref = $model->serialize(); |
|
121
|
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
Just like B<pack> except it drops the B<__CLASS__> field from the resulting |
|
123
|
|
|
|
|
|
|
hash reference. |
|
124
|
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
=head1 SEE ALSO |
|
126
|
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
=over 4 |
|
128
|
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
=item * |
|
130
|
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
L<MooseX::Storage> |
|
132
|
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
=back |
|
134
|
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
=cut |