File Coverage

blib/lib/DBIx/Class/Helper/ResultSet/Me.pm
Criterion Covered Total %
statement 10 10 100.0
branch n/a
condition 2 2 100.0
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::ResultSet::Me;
2             $DBIx::Class::Helper::ResultSet::Me::VERSION = '2.034002';
3             # ABSTRACT: Define predefined searches more nicely
4              
5 55     55   21815 use strict;
  55         109  
  55         1317  
6 55     55   233 use warnings;
  55         97  
  55         1290  
7              
8 55     55   233 use parent 'DBIx::Class::ResultSet';
  55         91  
  55         231  
9              
10 7   100 7 1 828 sub me { join('.', shift->current_source_alias, shift || q{}) }
11              
12             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) 2019 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