updated Changes
[dbsrgits/DBIx-Class-ResultSet-HashRef.git] / lib / DBIx / Class / ResultSet / HashRef.pm
CommitLineData
8d028daa 1package DBIx::Class::ResultSet::HashRef;
2
3use warnings;
4use strict;
5use base qw( DBIx::Class::ResultSet );
6use DBIx::Class::ResultClass::HashRefInflator;
7
8our $VERSION = '1.000';
9
10=head1 NAME
11
12DBIx::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
33This is a simple way to allow you to set result_class to L<DBIx::Class::ResultClass::HashRefInflator> to
34skip 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
47Sets result_class to L<DBIx::Class::ResultClass::HashRefInflator> and returns the resultset.
48
49=cut
50
51sub hashref_rs {
52 my ($self) = @_;
53 $self->result_class('DBIx::Class::ResultClass::HashRefInflator');
54 return $self;
55}
56
57=head2 hashref_array( )
58
59Calls ->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
69sub hashref_array {
70 return wantarray ? shift->hashref_rs->all : [ shift->hashref_rs->all ];
71}
72
73=head2 hashref_first( )
74
75Returns 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
82sub hashref_first {
83 return shift->hashref_rs->first;
84}
85
86=head1 AUTHOR
87
88Johannes Plunien E<lt>plu@cpan.orgE<gt>
89
90=head1 COPYRIGHT AND LICENSE
91
92Copyright 2008 by Johannes Plunien
93
94This library is free software; you can redistribute it and/or modify
95it under the same terms as Perl itself.
96
97Thanks 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
1111;