1DBIx::Class::Helper::RoUws:e:rPrCooxnDytBRrIeixsb:uu:ltCtelSdaestPsMe:er:tlHheoDldop(ce3ur)m:e:nRtoawt:i:oPnroxyResultSetMethod(3)
2
3
4
6 DBIx::Class::Helper::Row::ProxyResultSetMethod - Efficiently reuse
7 ResultSet methods from results with fallback
8
10 ResultSet:
11
12 package MyApp::Schema::ResultSet::Foo;
13
14 use parent 'DBIx::Class::ResultSet';
15
16 __PACKAGE__->load_components(qw(
17 Helper::ResultSet::CorrelateRelationship
18 ));
19
20 ...;
21
22 sub with_friend_count {
23 shift->search(undef, {
24 '+columns' => {
25 'friend_count' => $self->correlate('friends')->count_rs->as_query,
26 },
27 })
28 }
29
30 Result:
31
32 package MyApp::Schema::Result::Foo;
33
34 use parent 'DBIx::Class::Core';
35
36 __PACKAGE__->load_components(qw( Helper::Row::ProxyResultSetMethod ));
37
38 __PACKAGE__->proxy_resultset_method('friend_count');
39
40 or with DBIx::Class::Candy:
41
42 package MyApp::Schema::Result::Foo;
43
44 use DBIx::Class::Candy -components => ['Helper::Row::ProxyResultSetMethod'];
45
46 proxy_resultset_method 'friend_count';
47
48 Elsewhere:
49
50 my $row = $foo_rs->first;
51 say $row->friend_count . ' friends';
52
54 This module makes reusing resultset methods from a result trivially
55 easy. You should be using it.
56
58 proxy_resultset_method
59 __PACKAGE__->proxy_resultset_method( $name => {
60 slot => $slot,
61 resultset_method => $rs_method
62 });
63
64 "proxy_resultset_method"'s first argument is the name of the method to
65 generate and is required. The other two arguments, $slot, and
66 $resultset_method are optional. If unspecified $slot will default to
67 $name and $resultset_method will default to "with_$name". $slot is the
68 column that the data being retrieved is stored as in the ResultSet
69 method being proxied to. $resultset_method is (duh) the ResultSet
70 method being proxied to.
71
72 If you did not call the "with_*" method on your ResultSet, and call the
73 proxy method, it will transparently fallback and do the call and fetch
74 the needed data. E.g.:
75
76 my $foo = $schema->resultset('Foo')->first; ## did not call with_friend_count
77 print $foo->friend_count; ## will produce desired result magically
78
80 If used in conjunction with DBIx::Class::Candy this component will
81 export:
82
83 proxy_resultset_method
84
86 This module is dedicated to Ray Bradbury, who wrote Something Wicked
87 This Way Comes, Dandelion Wine, and numerous short stories, plays, etc
88 etc. Read this author's books.
89
91 Arthur Axel "fREW" Schmidt <frioux+cpan@gmail.com>
92
94 This software is copyright (c) 2020 by Arthur Axel "fREW" Schmidt.
95
96 This is free software; you can redistribute it and/or modify it under
97 the same terms as the Perl 5 programming language system itself.
98
99
100
101perl v5.32.1 DBIx:2:0C2l1a-s0s1:-:2H7elper::Row::ProxyResultSetMethod(3)