File Coverage

blib/lib/DBIx/Class/Helper/ResultSet/Util.pm
Criterion Covered Total %
statement 13 13 100.0
branch 4 6 66.6
condition n/a
subroutine 4 4 100.0
pod 1 1 100.0
total 22 24 91.6


line stmt bran cond sub pod time code
1             package DBIx::Class::Helper::ResultSet::Util;
2             $DBIx::Class::Helper::ResultSet::Util::VERSION = '2.034002';
3 55     55   354 use strict;
  55         107  
  55         1282  
4 55     55   238 use warnings;
  55         89  
  55         1713  
5              
6             # ABSTRACT: Helper utilities for DBIx::Class ResultSets
7              
8 55         631 use Sub::Exporter::Progressive -setup => {
9             exports => [
10             qw( correlate ),
11             ],
12 55     55   273 };
  55         100  
13              
14              
15             my $recent_dbic;
16             sub correlate {
17 2     2 1 5 my ($rs, $rel) = @_;
18              
19 2         7 my $source = $rs->result_source;
20              
21 2 50       24 $recent_dbic = $source->can('resolve_relationship_condition') ? 1 : 0
    100          
22             if not defined $recent_dbic;
23              
24             return $source->related_source($rel)->resultset
25             ->search(
26              
27             ($recent_dbic
28              
29             ? $source->resolve_relationship_condition(
30             rel_name => $rel,
31             foreign_alias => "${rel}_alias",
32             self_alias => $rs->current_source_alias,
33             )->{condition}
34              
35             : scalar $source->_resolve_condition(
36             $source->relationship_info($rel)->{cond},
37 2 50       11 "${rel}_alias",
38             $rs->current_source_alias,
39             $rel
40             )
41              
42             ),
43              
44             { alias => "${rel}_alias" }
45             );
46             }
47              
48             1;
49              
50             __END__
51              
52             =pod
53              
54             =head1 NAME
55              
56             DBIx::Class::Helper::ResultSet::Util - Helper utilities for DBIx::Class ResultSets
57              
58             =head1 DESCRIPTION
59              
60             These functions will slowly become the core implementations of many existing
61             components. The reason for this is that often you are not able to or unwilling
62             to add a component to an object, as adding the component fundamentally changes
63             the object. If instead you merely act on the object with a subroutine you are
64             not committing as seriously.
65              
66             =head1 EXPORTS
67              
68             =head2 correlate
69              
70             correlate($author_rs, 'books')
71              
72             This function allows you to correlate a resultset with one of it's
73             relationships. It takes the ResultSet and relationship name as arguments. See
74             L<DBIx::Class::Helper::ResultSet::CorrelateRelationship/SYNOPSIS> for an in
75             depth example.
76              
77             =head1 AUTHOR
78              
79             Arthur Axel "fREW" Schmidt <frioux+cpan@gmail.com>
80              
81             =head1 COPYRIGHT AND LICENSE
82              
83             This software is copyright (c) 2019 by Arthur Axel "fREW" Schmidt.
84              
85             This is free software; you can redistribute it and/or modify it under
86             the same terms as the Perl 5 programming language system itself.
87              
88             =cut