| 1 | package DBIx::Class::Helper::Row::SelfResultSet; | ||
| 2 | 54 | $DBIx::Class::Helper::Row::SelfResultSet::VERSION = '2.033001'; | |
| 3 | # ABSTRACT: Easily use ResultSet methods for the current row | ||
| 4 | |||
| 5 | 54 | ▶ | use strict; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 6 | 54 | ▶ | use warnings; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 7 | |||
| 8 | 54 | ▶ | use parent 'DBIx::Class::Row'; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 9 | |||
| 10 | sub self_rs { | ||
| 11 | 24 | ▶ | my ($self) = @_; |
|
Subroutine
self_rs: called CC=1 SCAR=0.0
Pod
documented
| |||
| 12 | |||
| 13 | 24 | my $rs = $self->result_source->resultset; | |
| 14 | 24 | return $rs->search( $self->ident_condition( $rs->current_source_alias ) ); | |
| 15 | } | ||
| 16 | |||
| 17 | 54 | 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) 2016 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 | ||