Helper/ResultSet/VirtualView.pm untested

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