Mongoose/Class.pm

filter: Statementstmt 30.0% 9 / 30 Branchbran 0.0% 0 / 6 Conditioncond 0.0% 0 / 12 MC/DCmcdc 0.0% 0 / 7 Subroutinesub 33.3% 2 / 6 Podpod 100% 3 / 3 totaltotal 21.8% 14 / 64 CC 9 SCAR 31.8
CC
9
Cov
19%
has_one
42.0
has_many
20.0
__ANON__
2.0
CRAP 24.1
« Mongoose/Engine.pm ↑ Summary Mongoose/Join.pm »
1 package Mongoose::Class;
2 2 $Mongoose::Class::VERSION = '2.02';
3 2 ▶use Moose ();
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use Moose::Exporter;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 2 Moose::Exporter->setup_import_methods(
7 with_meta => [ 'has_many', 'belongs_to', 'has_one' ],
8 also => 'Moose',
9 );
10  
11 0 ▶sub has_many {
Subroutine has_many: not called CC=4 SCAR=30.0
Pod documented
12 0 my ( $meta, $name ) = ( shift, shift );
13 0 ▶ my %options = @_ == 1 ? ( isa => shift ) : @_;
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 ? : 0 0 0
14 0 my $isa_original = $options{isa};
15  
16 0 $options{isa} = 'Mongoose::Join[' . $options{isa} . ']';
17 0 ▶ $options{default} ||= sub{ Mongoose::Join->new( with_class => "$isa_original" ) };
Subroutine __ANON__: not called CC=1 SCAR=6.9
Condition0%0/3
$options{"default"} ||= sub { "Mongoose::Join"->new("with_class", "$isa_original"); }
l!l&&r!l&&!r
000
MC/DC0%0/2
$options{"default"} ||= sub { "Mongoose::Join"->new("with_class", "$isa_original"); }
$options{"default"} sub { "Mongoose::Join"->new("with_class", "$isa_original"); }
Truth table0%0/3
A ||= B
A= $options{"default"}B= sub { "Mongoose::Join"->new("with_class", "$isa_original"); }
ABresult
1X1
011
000
18 0 ▶ $options{is} ||= 'ro';
Condition0%0/2
$options{"is"} ||= "ro"
l!l
00
MC/DC0%0/1
$options{"is"} ||= "ro"
$options{"is"}
Truth table0%0/2
A
A= $options{"is"}
Aresult
11
00
19  
20 0 $meta->add_attribute( $name, %options );
21 }
22  
23 0 ▶sub has_one {
Subroutine has_one: not called CC=6 SCAR=37.4
Pod documented
24 0 my $meta = shift;
25 0 my $name = shift;
26 0 my %options;
27 0 ▶ if ( @_ > 0 && @_ % 2 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ > 0 and @_ % 2) { } 0 0 0
Condition0%0/3
@_ > 0 and @_ % 2
!ll&&!rl&&r
000
MC/DC0%0/2
@_ > 0 and @_ % 2
@_ > 0 @_ % 2
Truth table0%0/3
A and B
A= @_ > 0B= @_ % 2
ABresult
0X0
100
111
28 0 $options{isa} = shift;
29 0 $options{is} = 'rw';
30 0 ▶ if( @_ > 1 ) { # allow: has_one 'att' => 'Str', required=>1;
Branch: 1 branch
BranchTrueFalseTotal
if (@_ > 1) 0 0 0
31 0 %options = ( %options, @_ );
32 }
33 }
34 else {
35 0 %options = @_;
36 0 ▶ $options{isa} ||= 'Any';
Condition0%0/2
$options{"isa"} ||= "Any"
l!l
00
MC/DC0%0/1
$options{"isa"} ||= "Any"
$options{"isa"}
Truth table0%0/2
A
A= $options{"isa"}
Aresult
11
00
37 0 ▶ $options{is} ||= 'rw';
Condition0%0/2
$options{"is"} ||= "rw"
l!l
00
MC/DC0%0/1
$options{"is"} ||= "rw"
$options{"is"}
Truth table0%0/2
A
A= $options{"is"}
Aresult
11
00
38 }
39  
40 0 $meta->add_attribute( $name, %options, );
41 }
42  
43 0 ▶sub belongs_to { goto &has_one }
Subroutine belongs_to: not called CC=1 SCAR=6.9
Pod documented
44  
45 =head1 NAME
46  
47 Mongoose::Class - sugary Mongoose-oriented replacement for Moose
48  
49 =head1 SYNOPSIS
50  
51 package MySchema::Person;
52 use Mongoose::Class; # uses Moose for you
53 with 'Mongoose::Document';
54  
55 has 'name' => ( is => 'rw', isa => 'Str' );
56 has_many 'siblings' => ( is => 'rw', isa => 'Person' );
57 belongs_to 'club' => ( is => 'rw', isa => 'Club' );
58 has_one 'father' => ( is => 'rw', isa => 'Person' );
59  
60 =head1 DESCRIPTION
61  
62 This is very much a work-in-progress.
63  
64 Basically, this module adds some sugar into your Mongoose
65 Document class by defining some stand-in replacements for
66 Moose's own C<has>.
67  
68 has_many
69 has_one
70 belongs_to
71  
72 The idea: fewer keystrokes and improved readability
73 by self-documenting your class.
74  
75 =head1 METHODS
76  
77 =head2 has_one
78  
79 Wrapper around Moose's own C<has>, but allows
80 for a shorter syntax:
81  
82 has_one 'name'; # isa=>'Any', is=>'rw' added
83 has_one 'age' => 'Num'; # is=>'rw' added
84 has_one 'age' => 'Num', default=>99;
85  
86 =head2 belongs_to
87  
88 It's the same as using C<has_one> from above.
89 It exists to improve your code expressiveness.
90  
91 =head2 has_many
92  
93 Wraps the defined relationship with another class using C<Mongoose::Join>.
94  
95 This:
96  
97 has_many 'employees' => ( isa=>'Employee' );
98  
99 # or
100  
101 has_many 'employees' => 'Employee';
102  
103 Becomes this:
104  
105 has 'employees' => (
106 is => 'ro',
107 isa => 'Mongoose::Join[Employee]',
108 default => sub { Mongoose::Join->new( with_class=>'Employee' ) }
109 );
110  
111 =cut
112  
113 2 1;
« Mongoose/Engine.pm ↑ Summary Mongoose/Join.pm »