File Coverage

blib/lib/DBIx/Class/Helper/Row/SelfResultSet.pm
Criterion Covered Total %
statement 12 12 100.0
branch n/a
condition n/a
subroutine 4 4 100.0
pod 1 1 100.0
total 17 17 100.0


line stmt bran cond sub pod time code
1             package DBIx::Class::Helper::Row::SelfResultSet;
2             $DBIx::Class::Helper::Row::SelfResultSet::VERSION = '2.035000';
3             # ABSTRACT: Easily use ResultSet methods for the current row
4              
5 56     56   28749 use strict;
  56         139  
  56         1673  
6 56     56   299 use warnings;
  56         132  
  56         1559  
7              
8 56     56   341 use parent 'DBIx::Class::Row';
  56         133  
  56         365  
9              
10             sub self_rs {
11 25     25 1 64441 my ($self) = @_;
12              
13 25         109 my $rs = $self->result_source->resultset;
14 25         7040 return $rs->search( $self->ident_condition( $rs->current_source_alias ) );
15             }
16              
17             1;
18              
19             __END__
20              
21             =pod
22              
23             =head1 NAME
24              
25             DBIx::Class::Helper::Row::SelfResultSet - Easily use ResultSet methods for the current row
26              
27             =head1 SYNOPSIS
28              
29             In result class:
30              
31             __PACKAGE__->load_components('Helper::Row::SelfResultSet');
32              
33             Elsewhere:
34              
35             $row->self_rs->$some_rs_method->single
36              
37             =head1 DESCRIPTION
38              
39             Sometimes you need to be able to access a ResultSet containing just the current
40             row. A good reason to do that would be if you had a ResultSet method that adds
41             in some calculated data, like counts of a relationship. You could use this to
42             get at that counted data without duplicating the logic for the counting.
43              
44             Due to primitives provided by L<DBIx::Class::PK> this references the current
45             values, or in C<DBIx::Class> terms, the dirty values. So if you modify the
46             primary columns it will be temporarily incorrect. For what it's worth I'm not
47             married to this behavior and I'd rather you get in touch with me before you
48             depend on it.
49              
50             =head1 METHODS
51              
52             =head2 self_rs
53              
54             $row->self_rs
55              
56             returns a ResultSet containing B<just> the current row.
57              
58             =head1 AUTHOR
59              
60             Arthur Axel "fREW" Schmidt <frioux+cpan@gmail.com>
61              
62             =head1 COPYRIGHT AND LICENSE
63              
64             This software is copyright (c) 2020 by Arthur Axel "fREW" Schmidt.
65              
66             This is free software; you can redistribute it and/or modify it under
67             the same terms as the Perl 5 programming language system itself.
68              
69             =cut