line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package DBIx::Class::Helper::Row::ProxyResultSetUpdate; |
2
|
|
|
|
|
|
|
$DBIx::Class::Helper::Row::ProxyResultSetUpdate::VERSION = '2.036000'; |
3
|
|
|
|
|
|
|
# ABSTRACT: Efficiently reuse ResultSet updates from results |
4
|
|
|
|
|
|
|
|
5
|
56
|
|
|
56
|
|
1568684
|
use strict; |
|
56
|
|
|
|
|
171
|
|
|
56
|
|
|
|
|
1624
|
|
6
|
56
|
|
|
56
|
|
290
|
use warnings; |
|
56
|
|
|
|
|
116
|
|
|
56
|
|
|
|
|
1548
|
|
7
|
|
|
|
|
|
|
|
8
|
56
|
|
|
56
|
|
288
|
use parent 'DBIx::Class::Helper::Row::SelfResultSet', 'DBIx::Class::Row'; |
|
56
|
|
|
|
|
119
|
|
|
56
|
|
|
|
|
1650
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
sub update { |
11
|
2
|
|
|
2
|
1
|
4927
|
my ($self, $upd) = @_; |
12
|
|
|
|
|
|
|
|
13
|
2
|
50
|
|
|
|
22
|
$self->set_inflated_columns($upd) if $upd; |
14
|
|
|
|
|
|
|
|
15
|
2
|
50
|
|
|
|
417
|
my %to_update = $self->get_dirty_columns |
16
|
|
|
|
|
|
|
or return $self; |
17
|
|
|
|
|
|
|
|
18
|
2
|
50
|
|
|
|
38
|
$self->throw_exception( "Not in database" ) unless $self->in_storage; |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
# copied directly from DBIx::Class::Row except for this line |
21
|
2
|
|
|
|
|
12
|
my $rows = $self->self_rs->update(\%to_update); |
22
|
2
|
100
|
|
|
|
3196
|
if ($rows == 0) { |
|
|
50
|
|
|
|
|
|
23
|
1
|
|
|
|
|
69
|
$self->throw_exception( "Can't update ${self}: row not found" ); |
24
|
|
|
|
|
|
|
} elsif ($rows > 1) { |
25
|
0
|
|
|
|
|
0
|
$self->throw_exception("Can't update ${self}: updated more than one row"); |
26
|
|
|
|
|
|
|
} |
27
|
1
|
|
|
|
|
32
|
$self->{_dirty_columns} = {}; |
28
|
1
|
|
|
|
|
4
|
$self->{related_resultsets} = {}; |
29
|
1
|
|
|
|
|
3
|
delete $self->{_column_data_in_storage}; |
30
|
1
|
|
|
|
|
4
|
return $self; |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
1; |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
__END__ |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
=pod |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
=head1 NAME |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
DBIx::Class::Helper::Row::ProxyResultSetUpdate - Efficiently reuse ResultSet updates from results |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
=head1 SYNOPSIS |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
ResultSet: |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
package MyApp::Schema::ResultSet::Foo; |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
use parent 'DBIx::Class::ResultSet'; |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
sub update { |
52
|
|
|
|
|
|
|
my ($self, $data) = @_; |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
die 'you fool!' if $data->{name} eq 'fool'; |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
return $self->next::method($data); |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
Result: |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
package MyApp::Schema::Result::Foo; |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
use parent 'DBIx::Class::Core'; |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
__PACKAGE__->load_components(qw( Helper::Row::ProxyResultSetUpdate )); |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
... |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
or with L<DBIx::Class::Candy>: |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
package MyApp::Schema::Result::Foo; |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
use DBIx::Class::Candy -components => ['Helper::Row::ProxyResultSetMethod']; |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
... |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
=head1 DESCRIPTION |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
This module makes reusing resultset updates from a result trivially easy. |
80
|
|
|
|
|
|
|
Often the only way that people share update methods is by overriding update |
81
|
|
|
|
|
|
|
in their resultset to use L<DBIx::Class::ResultSet/update_all>. Unfortunately, |
82
|
|
|
|
|
|
|
that can end up being wildly inefficient. Instead, if you can write your |
83
|
|
|
|
|
|
|
update in terms of the resultset, you can make your code much faster and more |
84
|
|
|
|
|
|
|
efficient. |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
=head1 AUTHOR |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
Arthur Axel "fREW" Schmidt <frioux+cpan@gmail.com> |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
This software is copyright (c) 2020 by Arthur Axel "fREW" Schmidt. |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
95
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
=cut |