Commit | Line | Data |
8d028daa |
1 | package DBIx::Class::ResultSet::HashRef; |
2 | |
3 | use warnings; |
4 | use strict; |
5 | use base qw( DBIx::Class::ResultSet ); |
6 | use DBIx::Class::ResultClass::HashRefInflator; |
7 | |
8 | our $VERSION = '1.000'; |
9 | |
10 | =head1 NAME |
11 | |
12 | DBIx::Class::ResultSet::HashRef - Adds syntatic sugar to skip the fancy objects |
13 | |
14 | =head1 SYNOPSIS |
15 | |
16 | # in your resultsource class |
17 | __PACKAGE__->resultset_class( 'DBIx::Class::ResultSet::HashRef' ); |
18 | |
19 | # in your calling code |
20 | my $rs = $schema->resultset('User')->search( { } )->hashref_rs; |
21 | while (my $row = $rs->next) { |
22 | print Dumper $row; |
23 | } |
24 | |
25 | You can chain up every L<DBIx::Class::ResultSet> method to ->hashref_rs: |
26 | |
27 | * ->hashref_rs->all (same as ->hashref_array) |
28 | |
29 | * ->hashref_rs->first (same as ->hashref_first) |
30 | |
31 | =head1 DESCRIPTION |
32 | |
33 | This is a simple way to allow you to set result_class to L<DBIx::Class::ResultClass::HashRefInflator> to |
34 | skip the fancy objects. |
35 | |
36 | =head1 INSTALLATION |
37 | |
38 | perl Makefile.PL |
39 | make |
40 | make test |
41 | make install |
42 | |
43 | =head1 METHODS |
44 | |
45 | =head2 hashref_rs( ) |
46 | |
47 | Sets result_class to L<DBIx::Class::ResultClass::HashRefInflator> and returns the resultset. |
48 | |
49 | =cut |
50 | |
51 | sub hashref_rs { |
52 | my ($self) = @_; |
53 | $self->result_class('DBIx::Class::ResultClass::HashRefInflator'); |
54 | return $self; |
55 | } |
56 | |
57 | =head2 hashref_array( ) |
58 | |
59 | Calls ->hashref_rs->all and returns depending on the calling context an array or an reference to an array. |
60 | |
61 | my $rs = $schema->resultset('User')->search( { } )->hashref_array; |
62 | print Dumper $rs; |
63 | |
64 | my @rs = $schema->resultset('User')->search( { } )->hashref_array; |
65 | print Dumper @rs; |
66 | |
67 | =cut |
68 | |
69 | sub hashref_array { |
70 | return wantarray ? shift->hashref_rs->all : [ shift->hashref_rs->all ]; |
71 | } |
72 | |
73 | =head2 hashref_first( ) |
74 | |
75 | Returns the first row of the resultset inflated by L<DBIx::Class::ResultClass::HashRefInflator>. |
76 | |
77 | my $first_row = $schema->resultset('User')->search( { } )->hashref_first; |
78 | print Dumper $first_row |
79 | |
80 | =cut |
81 | |
82 | sub hashref_first { |
83 | return shift->hashref_rs->first; |
84 | } |
85 | |
86 | =head1 AUTHOR |
87 | |
88 | Johannes Plunien E<lt>plu@cpan.orgE<gt> |
89 | |
90 | =head1 COPYRIGHT AND LICENSE |
91 | |
92 | Copyright 2008 by Johannes Plunien |
93 | |
94 | This library is free software; you can redistribute it and/or modify |
95 | it under the same terms as Perl itself. |
96 | |
97 | Thanks to mst for his patience. |
98 | |
99 | =head1 SEE ALSO |
100 | |
101 | =over 4 |
102 | |
103 | =item * L<DBIx::Class> |
104 | |
105 | =item * L<DBIx::Class::ResultClass::HashRefInflator> |
106 | |
107 | =back |
108 | |
109 | =cut |
110 | |
111 | 1; |