Async/ResultSetColumn.pm

filter: Statementstmt 96.0% 24 / 25 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 90.9% 10 / 11 Podpod 100% 7 / 7 totaltotal 95.3% 41 / 43 CC 1 SCAR 0.9
CC
1
Cov
96%
avg
2.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.1
« Async/Exception/RelationshipAsColumn.pm ↑ Summary Async/Exception/AmbiguousColumn.pm »
1 package DBIx::Class::Async::ResultSetColumn;
2  
3 100 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 100 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 100 ▶use version;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 100 our $VERSION = qv('v1.2.0');
8 100 our $AUTHORITY = 'cpan:MANWAR';
9  
10 =head1 NAME
11  
12 DBIx::Class::Async::ResultSetColumn - Asynchronous operations on a single ResultSource column
13  
14 =head1 VERSION
15  
16 Version v1.2.0
17  
18 =head1 SYNOPSIS
19  
20 my $rs = $schema->resultset('Invoice')->search({ status => 'unpaid' });
21 my $col = $rs->get_column('amount');
22  
23 # All methods return a Future
24 $col->sum->then(sub {
25 my $total = shift;
26 say "Total unpaid: $total";
27 });
28  
29 $col->max->on_done(sub {
30 my $highest = shift;
31 say "Highest unpaid invoice: $highest";
32 });
33  
34 =head1 DESCRIPTION
35  
36 A C<ResultSetColumn> object represents a specific column within a L<DBIx::Class::Async::ResultSet>.
37 It is used to perform aggregate operations (like summation or averaging) or to fetch
38 single-column data sets asynchronously.
39  
40 This object is typically obtained by calling C<get_column> on a
41 L<DBIx::Class::Async::ResultSet> object.
42  
43 =head1 METHODS
44  
45 =head2 sum
46  
47 Returns a L<Future> resolving to the sum of all values in the column.
48  
49 =head2 max / min
50  
51 Returns a L<Future> resolving to the maximum or minimum value in the column,
52 respectively.
53  
54 =head2 avg / average
55  
56 Returns a L<Future> resolving to the average (mean) value of the column.
57  
58 =head2 count
59  
60 Returns a L<Future> resolving to the count of values in the column.
61  
62 =head1 INTERNAL METHODS
63  
64 =head2 new
65  
66 Instantiates a new column proxy. Requires C<resultset>, C<column>, and C<async_db>.
67  
68 =head2 _aggregate
69  
70 The core dispatcher that builds the worker payload. It extracts the current
71 search criteria from the parent ResultSet and appends the target column name
72 before calling the background worker.
73  
74 =cut
75  
76 4 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod documented
77 4 my ($class, %args) = @_;
78 return bless {
79 _resultset => $args{resultset},
80 _column => $args{column},
81 _async_db => $args{async_db},
82 4 }, $class;
83 }
84  
85 1 ▶sub sum { shift->_aggregate('sum') }
Subroutine sum: called CC=1 SCAR=0.0
Pod documented
86 1 ▶sub max { shift->_aggregate('max') }
Subroutine max: called CC=1 SCAR=0.0
Pod documented
87 1 ▶sub min { shift->_aggregate('min') }
Subroutine min: called CC=1 SCAR=0.0
Pod documented
88 0 ▶sub avg { shift->_aggregate('avg') }
Subroutine avg: not called CC=1 SCAR=6.9
Pod documented
89 1 ▶sub count { shift->_aggregate('count') }
Subroutine count: called CC=1 SCAR=0.0
Pod documented
90 1 ▶sub average { shift->_aggregate('average') }
Subroutine average: called CC=1 SCAR=0.0
Pod documented
91  
92 5 ▶sub _aggregate {
Subroutine _aggregate: called CC=1 SCAR=0.0
93 5 my ($self, $func) = @_;
94 5 my $db = $self->{_async_db};
95  
96 5 my $payload = $self->{_resultset}->_build_payload();
97  
98 5 $payload->{column} = $self->{_column};
99  
100 # We reuse the parent ResultSet's bridge and payload logic
101 5 return DBIx::Class::Async::_call_worker(
102 $db,
103 $func,
104 $payload,
105 );
106 }
107  
108 =head1 AUTHOR
109  
110 Mohammad Sajid Anwar, C<< <mohammad.anwar at yahoo.com> >>
111  
112 =head1 REPOSITORY
113  
114 L<https://github.com/manwar/DBIx-Class-Async>
115  
116 =head1 BUGS
117  
118 Please report any bugs or feature requests through the web interface at L<https://github.com/manwar/DBIx-Class-Async/issues>.
119 I will be notified and then you'll automatically be notified of progress on your
120 bug as I make changes.
121  
122 =head1 SUPPORT
123  
124 You can find documentation for this module with the perldoc command.
125  
126 perldoc DBIx::Class::Async::ResultSetColumn
127  
128 You can also look for information at:
129  
130 =over 4
131  
132 =item * BUG Report
133  
134 L<https://github.com/manwar/DBIx-Class-Async/issues>
135  
136 =item * CPAN Ratings
137  
138 L<http://cpanratings.perl.org/d/DBIx-Class-Async>
139  
140 =item * Search MetaCPAN
141  
142 L<https://metacpan.org/dist/DBIx-Class-Async/>
143  
144 =back
145  
146 =head1 LICENSE AND COPYRIGHT
147  
148 Copyright (C) 2026 Mohammad Sajid Anwar.
149  
150 This program is free software; you can redistribute it and / or modify it under
151 the terms of the the Artistic License (2.0). You may obtain a copy of the full
152 license at:
153 L<http://www.perlfoundation.org/artistic_license_2_0>
154 Any use, modification, and distribution of the Standard or Modified Versions is
155 governed by this Artistic License.By using, modifying or distributing the Package,
156 you accept this license. Do not use, modify, or distribute the Package, if you do
157 not accept this license.
158 If your Modified Version has been derived from a Modified Version made by someone
159 other than you,you are nevertheless required to ensure that your Modified Version
160 complies with the requirements of this license.
161 This license does not grant you the right to use any trademark, service mark,
162 tradename, or logo of the Copyright Holder.
163 This license includes the non-exclusive, worldwide, free-of-charge patent license
164 to make, have made, use, offer to sell, sell, import and otherwise transfer the
165 Package with respect to any patent claims licensable by the Copyright Holder that
166 are necessarily infringed by the Package. If you institute patent litigation
167 (including a cross-claim or counterclaim) against any party alleging that the
168 Package constitutes direct or contributory patent infringement,then this Artistic
169 License to you shall terminate on the date that such litigation is filed.
170 Disclaimer of Warranty: THE PACKAGE IS PROVIDED BY THE COPYRIGHT HOLDER AND
171 CONTRIBUTORS "AS IS' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES. THE IMPLIED
172 WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR
173 NON-INFRINGEMENT ARE DISCLAIMED TO THE EXTENT PERMITTED BY YOUR LOCAL LAW. UNLESS
174 REQUIRED BY LAW, NO COPYRIGHT HOLDER OR CONTRIBUTOR WILL BE LIABLE FOR ANY DIRECT,
175 INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING IN ANY WAY OUT OF THE USE
176 OF THE PACKAGE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
177  
178 =cut
179  
180 100 1; # End of DBIx::Class::Async::ResultSetColumn
« Async/Exception/RelationshipAsColumn.pm ↑ Summary Async/Exception/AmbiguousColumn.pm »