Mongoose/Document.pm

filter: Statementstmt 92.4% 49 / 53 Branchbran 75.0% 9 / 12 Conditioncond 40.0% 2 / 5 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 100% 8 / 8 Podpod n/a totaltotal 83.9% 68 / 81 CC 9 SCAR 17.9
CC
9
Cov
86%
__ANON__
9.9
BEGIN
1.0
BEGIN
1.0
CRAP 6.0
« Mongoose/Cursor.pm ↑ Summary Mongoose/Role/Naming.pm »
1 package Mongoose::Document;
2 1 $Mongoose::Document::VERSION = '2.02';
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use Mongoose;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use Mongoose::Join;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use Mongoose::File;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use MooseX::Role::Parameterized;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use Mongoose::Meta::AttributeTraits;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 1 parameter '-engine' => ( isa => 'Mongoose::Role::Engine', );
11 1 parameter '-collection_name' => ( isa => 'Str', );
12 1 parameter '-pk' => ( isa => 'ArrayRef[Str]', );
13 1 parameter '-as' => ( isa => 'Str', );
14  
15 2 ▶role {
Subroutine __ANON__: called CC=9 SCAR=22.9
16 2 my $p = shift;
17 2 my %args = @_;
18 2 my $class_name;
19 2 ▶ if ( $args{consumer}->isa('Moose::Meta::Class') ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args{'consumer'}->isa('Moose::Meta::Class')) { } 1 1 2
20 1 $class_name = $args{consumer}->name;
21 }
22 else {
23 # If we get into this block of code, it means that Mongoose was consumed
24 # not by a class but by another (intermediate) role. Mongoose needs to
25 # know the original class for various reasons (naming the collection
26 # name being the most obvious one but not the only one).
27 # What follows is an ugly hack to climb back up the consumption hierarchy
28 # to find out the name of the class which was originally used. If anyone
29 # can do it differently than it has to be better than the below!
30 # -- Allan Whiteford
31 1 my $i=1;
32 1 ▶ while ( my @caller = do { package
Branch: 1 branch
BranchTrueFalseTotal
if (my(@caller) = do { package DB; caller $i++ }) 11 0 11
33 11 DB; caller( $i++ ) } )
34 {
35 11 ▶ if ( $caller[3] eq 'MooseX::Role::Parameterized::Meta::Trait::Parameterizable::generate_role' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($caller[3] eq "MooseX::Role::Parameterized::Meta::Trait::Parameterizable::generate_role") 2 9 11
36 2 my @args = @DB::args;
37 2 my %args = @args[1..$#args];
38 2 ▶ if ($args{'consumer'}->isa('Moose::Meta::Class')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args{"consumer"}->isa("Moose::Meta::Class")) 1 1 2
39 1 $class_name = $args{'consumer'}->name;
40 1 last;
41 }
42 }
43 }
44 }
45  
46 2 ▶ die("Cannot find a class name to use") unless($class_name);
Branch: 1 branch
BranchTrueFalseTotal
unless $class_name 0 2 2
47  
48 2 ▶ my $collection_name = $p->{'-collection_name'} || do{ Mongoose->naming->("$class_name") };
Condition33%1/3
$p->{'-collection_name'} || do { 'Mongoose'->naming->("$class_name") }
l!l&&r!l&&!r
020
MC/DC0%0/2
$p->{'-collection_name'} || do { 'Mongoose'->naming->("$class_name") }
$p->{'-collection_name'} do { 'Mongoose'->naming->("$class_name") }
Truth table33%1/3
A || B
A= $p->{'-collection_name'}B= do { 'Mongoose'->naming->("$class_name") }
ABresult
1X1
011
000
49  
50 # load the selected engine and consume it
51 2 ▶ with( $p->{'-engine'} || 'Mongoose::Engine' );
Condition50%1/2
$p->{'-engine'} || 'Mongoose::Engine'
l!l
02
MC/DC0%0/1
$p->{'-engine'} || 'Mongoose::Engine'
$p->{'-engine'}
Truth table50%1/2
A
A= $p->{'-engine'}
Aresult
11
00
52  
53 # attributes
54 2 has '_id' => ( is => 'rw', isa => 'BSON::OID', traits => ['DoNotMongoSerialize'] );
55  
56 # aliasing
57 2 ▶ if ( my $as = $p->{'-as'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $as = $p->{"-as"}) 0 2 2
58 1 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
59 0 *{ $as . "::" } = \*{ $class_name . "::" };
60 0 Mongoose->aliased( $as => $class_name );
61 }
62  
63 # Store this class config on mongoose
64 Mongoose->class_config( $class_name => {
65 pk => $p->{'-pk'},
66 2 as => $p->{'-as'},
67 collection_name => $collection_name,
68 });
69 1 };
70  
71 =head1 NAME
72  
73 Mongoose::Document - a Mongoose document role
74  
75 =head1 SYNOPSIS
76  
77 package Person;
78 use Moose;
79 with 'Mongoose::Document';
80 has 'name' => ( is => 'rw', isa => 'Str', required => 1 );
81  
82 =head1 SEE ALSO
83  
84 Read the Mongoose L<intro|Mongoose::Intro> or L<cookbook|Mongoose::Cookbook>.
85  
86 =cut
87  
88 1 1;
« Mongoose/Cursor.pm ↑ Summary Mongoose/Role/Naming.pm »