| 1 | package DBIx::Class::Helper::ResultSet::VirtualView; | ||
| 2 | $DBIx::Class::Helper::ResultSet::VirtualView::VERSION = '2.033001'; | ||
| 3 | # ABSTRACT: Clean up your SQL namespace (DEPRECATED) | ||
| 4 | |||
| 5 | use strict; | ||
| 6 | use warnings; | ||
| 7 | use vars qw($VERSION); | ||
| 8 | |||
| 9 | use parent 'DBIx::Class::ResultSet'; | ||
| 10 | |||
| 11 | sub as_virtual_view { | ||
| 12 | my $self = shift; | ||
| 13 | |||
| 14 | return $self->as_subselect_rs; | ||
| 15 | } | ||
| 16 | |||
| 17 | use Carp::Clan; | ||
| 18 | carp 'This module is deprecated! Please use DBIx::Class::ResultSet::as_subselect_rs instead!' if $VERSION >= 3; | ||
| 19 | croak 'This module is deprecated! Please use DBIx::Class::ResultSet::as_subselect_rs instead!' if $VERSION >= 4; | ||
| 20 | |||
| 21 | 1; | ||
| 22 | |||
| 23 | __END__ | ||
| 24 | |||
| 25 | =pod | ||
| 26 | |||
| 27 | =head1 NAME | ||
| 28 | |||
| 29 | DBIx::Class::Helper::ResultSet::VirtualView - Clean up your SQL namespace (DEPRECATED) | ||
| 30 | |||
| 31 | =head1 SYNOPSIS | ||
| 32 | |||
| 33 | # note that this is normally a component for a ResultSet | ||
| 34 | package MySchema::ResultSet::Bar; | ||
| 35 | |||
| 36 | use strict; | ||
| 37 | use warnings; | ||
| 38 | |||
| 39 | use parent 'DBIx::Class::ResultSet'; | ||
| 40 | |||
| 41 | __PACKAGE__->load_components('Helper::ResultSet::VirtualView'); | ||
| 42 | |||
| 43 | # and then in code that uses the ResultSet Join with relation x | ||
| 44 | my $rs = $schema->resultset('Bar')->search({'x.name' => 'abc'},{ join => 'x' }); | ||
| 45 | |||
| 46 | # 'x' now pollutes the query namespace | ||
| 47 | |||
| 48 | # So the following works as expected | ||
| 49 | my $ok_rs = $rs->search({'x.other' => 1}); | ||
| 50 | |||
| 51 | # But this doesn't: instead of finding a 'Bar' related to two x rows (abc and | ||
| 52 | # def) we look for one row with contradictory terms and join in another table | ||
| 53 | # (aliased 'x_2') which we never use | ||
| 54 | my $broken_rs = $rs->search({'x.name' => 'def'}); | ||
| 55 | |||
| 56 | my $rs2 = $rs->as_virtual_view; | ||
| 57 | |||
| 58 | # doesn't work - 'x' is no longer accessible in $rs2, having been sealed away | ||
| 59 | my $not_joined_rs = $rs2->search({'x.other' => 1}); | ||
| 60 | |||
| 61 | # works as expected: finds a 'table' row related to two x rows (abc and def) | ||
| 62 | my $correctly_joined_rs = $rs2->search({'x.name' => 'def'}); | ||
| 63 | |||
| 64 | =head1 DESCRIPTION | ||
| 65 | |||
| 66 | This component is will allow you to clean up your SQL namespace. See | ||
| 67 | L<DBIx::Class::Helper::ResultSet/NOTE> for a nice way to apply it to your | ||
| 68 | entire schema. | ||
| 69 | |||
| 70 | =head1 DEPRECATED | ||
| 71 | |||
| 72 | This component has been suplanted by | ||
| 73 | L<DBIx::Class::ResultSet::as_subselect_rs>. In the next major version | ||
| 74 | (3) we will begin issuing a warning on it's use. In the major version after | ||
| 75 | that (4) we will remove it entirely. | ||
| 76 | |||
| 77 | =head1 METHODS | ||
| 78 | |||
| 79 | =head2 as_virtual_view | ||
| 80 | |||
| 81 | Act as a barrier to SQL symbols. The resultset provided will be made into a | ||
| 82 | "virtual view" by including it as a subquery within the from clause. From this | ||
| 83 | point on, any joined tables are inaccessible to ->search on the resultset (as if | ||
| 84 | it were simply where-filtered without joins). See L</SYNOPSIS> for example. | ||
| 85 | |||
| 86 | =head1 NOTE | ||
| 87 | |||
| 88 | You don't I<have> to use this as a Component. If you prefer you can use it | ||
| 89 | in the following manner: | ||
| 90 | |||
| 91 | # in code using ResultSet: | ||
| 92 | use DBIx::Class:Helper::VirtualView; | ||
| 93 | |||
| 94 | my $new_rs = DBIx::Class::Helper::VirtualView::as_virtual_view($rs); | ||
| 95 | |||
| 96 | =head1 THANKS | ||
| 97 | |||
| 98 | Thanks to ijw from #dbix-class for the idea for this helper (originally called | ||
| 99 | seal), most of the code, and most of the documentation. | ||
| 100 | |||
| 101 | =head1 AUTHOR | ||
| 102 | |||
| 103 | Arthur Axel "fREW" Schmidt <frioux+cpan@gmail.com> | ||
| 104 | |||
| 105 | =head1 COPYRIGHT AND LICENSE | ||
| 106 | |||
| 107 | This software is copyright (c) 2016 by Arthur Axel "fREW" Schmidt. | ||
| 108 | |||
| 109 | This is free software; you can redistribute it and/or modify it under | ||
| 110 | the same terms as the Perl 5 programming language system itself. | ||
| 111 | |||
| 112 | =cut |