| 1 | package Catalyst::Controller::DBIC::API::JoinBuilder; | ||||||||||||||||||||
| 2 | 16 | $Catalyst::Controller::DBIC::API::JoinBuilder::VERSION = '2.009000'; | |||||||||||||||||||
| 3 | #ABSTRACT: Provides a helper class to automatically keep track of joins in complex searches | ||||||||||||||||||||
| 4 | 16 | ▶ | use Moose; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 5 | 16 | ▶ | use MooseX::Types::Moose(':all'); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 6 | 16 | ▶ | use Catalyst::Controller::DBIC::API::Types(':all'); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 7 | 16 | ▶ | use namespace::autoclean; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 8 | |||||||||||||||||||||
| 9 | |||||||||||||||||||||
| 10 | has parent => ( | ||||||||||||||||||||
| 11 | is => 'ro', | ||||||||||||||||||||
| 12 | isa => JoinBuilder, | ||||||||||||||||||||
| 13 | predicate => 'has_parent', | ||||||||||||||||||||
| 14 | weak_ref => 1, | ||||||||||||||||||||
| 15 | 17 | ▶ | trigger => sub { my ( $self, $new ) = @_; $new->add_child($self); }, | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 16 | 16 | ); | |||||||||||||||||||
| 17 | |||||||||||||||||||||
| 18 | |||||||||||||||||||||
| 19 | has children => ( | ||||||||||||||||||||
| 20 | is => 'ro', | ||||||||||||||||||||
| 21 | isa => ArrayRef [JoinBuilder], | ||||||||||||||||||||
| 22 | traits => ['Array'], | ||||||||||||||||||||
| 23 | 72 | ▶ | default => sub { [] }, | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 24 | 16 | handles => { | |||||||||||||||||||
| 25 | all_children => 'elements', | ||||||||||||||||||||
| 26 | has_children => 'count', | ||||||||||||||||||||
| 27 | add_child => 'push', | ||||||||||||||||||||
| 28 | } | ||||||||||||||||||||
| 29 | ); | ||||||||||||||||||||
| 30 | |||||||||||||||||||||
| 31 | |||||||||||||||||||||
| 32 | 16 | has joins => ( | |||||||||||||||||||
| 33 | is => 'ro', | ||||||||||||||||||||
| 34 | isa => HashRef, | ||||||||||||||||||||
| 35 | lazy_build => 1, | ||||||||||||||||||||
| 36 | ); | ||||||||||||||||||||
| 37 | |||||||||||||||||||||
| 38 | |||||||||||||||||||||
| 39 | 16 | has name => ( | |||||||||||||||||||
| 40 | is => 'ro', | ||||||||||||||||||||
| 41 | isa => Str, | ||||||||||||||||||||
| 42 | required => 1, | ||||||||||||||||||||
| 43 | ); | ||||||||||||||||||||
| 44 | |||||||||||||||||||||
| 45 | |||||||||||||||||||||
| 46 | 54 | ▶ | sub _build_joins { | ||||||||||||||||||
|
Subroutine
_build_joins: called CC=4 SCAR=16.3
| |||||||||||||||||||||
| 47 | 54 | my ($self) = @_; | |||||||||||||||||||
| 48 | |||||||||||||||||||||
| 49 | 54 | my $parent; | |||||||||||||||||||
| 50 | 54 | ▶ | while ( my $found = $self->parent ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 51 | 0 | ▶ | if ( $found->has_parent ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 52 | 0 | $self = $found; | |||||||||||||||||||
| 53 | 0 | next; | |||||||||||||||||||
| 54 | } | ||||||||||||||||||||
| 55 | 0 | $parent = $found; | |||||||||||||||||||
| 56 | } | ||||||||||||||||||||
| 57 | |||||||||||||||||||||
| 58 | 54 | my $builder; | |||||||||||||||||||
| 59 | 70 | ▶ | $builder = sub { | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 60 | 70 | my ($node) = @_; | |||||||||||||||||||
| 61 | 70 | my $foo = {}; | |||||||||||||||||||
| 62 | 70 | map { $foo->{ $_->name } = $builder->($_) } $node->all_children; | |||||||||||||||||||
| 63 | 70 | return $foo; | |||||||||||||||||||
| 64 | 54 | }; | |||||||||||||||||||
| 65 | |||||||||||||||||||||
| 66 | 54 | ▶ | return $builder->( $parent || $self ); | ||||||||||||||||||
|
Condition33%1/3
$parent || $self
MC/DC0%0/2
$parent || $self
$parent
$self
Truth table33%1/3
A || B
A= $parentB= $self
| |||||||||||||||||||||
| 67 | } | ||||||||||||||||||||
| 68 | |||||||||||||||||||||
| 69 | |||||||||||||||||||||
| 70 | 16 | 1; | |||||||||||||||||||
| 71 | |||||||||||||||||||||
| 72 | __END__ | ||||||||||||||||||||