| 1 | package DBIx::Class::Helper::ResultSet::Me; | ||||||||||||
| 2 | 54 | $DBIx::Class::Helper::ResultSet::Me::VERSION = '2.033001'; | |||||||||||
| 3 | # ABSTRACT: Define predefined searches more nicely | ||||||||||||
| 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::ResultSet'; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 9 | |||||||||||||
| 10 | 6 | ▶ | sub me { join('.', shift->current_source_alias, shift || q{}) } | ||||||||||
|
Subroutine
me: called CC=2 SCAR=6.9
Pod
documented
Condition100%2/2
shift() || ''
MC/DC100%1/1
shift() || ''
shift()
Truth table100%2/2
A
A= shift()
| |||||||||||||
| 11 | |||||||||||||
| 12 | 54 | 1; | |||||||||||
| 13 | |||||||||||||
| 14 | __END__ | ||||||||||||
| 15 | |||||||||||||
| 16 | =pod | ||||||||||||
| 17 | |||||||||||||
| 18 | =head1 NAME | ||||||||||||
| 19 | |||||||||||||
| 20 | DBIx::Class::Helper::ResultSet::Me - Define predefined searches more nicely | ||||||||||||
| 21 | |||||||||||||
| 22 | =head1 SYNOPSIS | ||||||||||||
| 23 | |||||||||||||
| 24 | # note that this is normally a component for a ResultSet | ||||||||||||
| 25 | package MySchema::ResultSet::Bar; | ||||||||||||
| 26 | |||||||||||||
| 27 | use strict; | ||||||||||||
| 28 | use warnings; | ||||||||||||
| 29 | |||||||||||||
| 30 | use parent 'DBIx::Class::ResultSet'; | ||||||||||||
| 31 | |||||||||||||
| 32 | use constant CANDY => 1; | ||||||||||||
| 33 | |||||||||||||
| 34 | __PACKAGE__->load_components('Helper::ResultSet::Me'); | ||||||||||||
| 35 | |||||||||||||
| 36 | sub candy { | ||||||||||||
| 37 | $_[0]->search({ $_[0]->me.'type' => CANDY }) | ||||||||||||
| 38 | } | ||||||||||||
| 39 | |||||||||||||
| 40 | sub cake { | ||||||||||||
| 41 | $_[0]->search({ $_[0]->me('type') => CAKE }) | ||||||||||||
| 42 | } | ||||||||||||
| 43 | |||||||||||||
| 44 | # in code using resultset: | ||||||||||||
| 45 | my $candy_bars = $schema->resultset('Bar')->candy; | ||||||||||||
| 46 | my $cake_bars = $schema->resultset('Bar')->cake; | ||||||||||||
| 47 | |||||||||||||
| 48 | =head1 DESCRIPTION | ||||||||||||
| 49 | |||||||||||||
| 50 | This component allows slightly nicer predefined search definition. See | ||||||||||||
| 51 | L<DBIx::Class::Helper::ResultSet/NOTE> for a nice way to apply it to your | ||||||||||||
| 52 | entire schema. | ||||||||||||
| 53 | |||||||||||||
| 54 | It defines a single method that is shorter and (to most) clearer than | ||||||||||||
| 55 | L<DBIx::Class::ResultSet/current_source_alias>, which is what it uses | ||||||||||||
| 56 | for the L</me> method. | ||||||||||||
| 57 | |||||||||||||
| 58 | =head1 METHODS | ||||||||||||
| 59 | |||||||||||||
| 60 | =head2 me | ||||||||||||
| 61 | |||||||||||||
| 62 | Merely returns the SQL namespace for the current search with a C<.> at the end, | ||||||||||||
| 63 | allowing internal resultset methods to be defined with C<< $self->me >> instead | ||||||||||||
| 64 | of C<< $self->current_source_alias . q(.) >>. Also, if you pass it a single | ||||||||||||
| 65 | argument it will append that to the returned string. | ||||||||||||
| 66 | |||||||||||||
| 67 | =head1 AUTHOR | ||||||||||||
| 68 | |||||||||||||
| 69 | Arthur Axel "fREW" Schmidt <frioux+cpan@gmail.com> | ||||||||||||
| 70 | |||||||||||||
| 71 | =head1 COPYRIGHT AND LICENSE | ||||||||||||
| 72 | |||||||||||||
| 73 | This software is copyright (c) 2016 by Arthur Axel "fREW" Schmidt. | ||||||||||||
| 74 | |||||||||||||
| 75 | This is free software; you can redistribute it and/or modify it under | ||||||||||||
| 76 | the same terms as the Perl 5 programming language system itself. | ||||||||||||
| 77 | |||||||||||||
| 78 | =cut | ||||||||||||