@@ -5,9 +5,12 @@ use strict;
5
5
use warnings;
6
6
7
7
use DBIx::Class::Carp;
8
- use Sub::Name ' subname' ;
9
- use Scalar::Util ' blessed' ;
10
- use DBIx::Class::_Util ' fail_on_internal_wantarray' ;
8
+ use DBIx::Class::_Util qw( fail_on_internal_wantarray quote_sub) ;
9
+
10
+ # FIXME - this souldn't be needed
11
+ my $cu ;
12
+ BEGIN { $cu = \&carp_unique }
13
+
11
14
use namespace::clean;
12
15
13
16
our %_pod_inherit_config =
@@ -26,10 +29,6 @@ sub many_to_many {
26
29
" missing foreign relation in many-to-many"
27
30
) unless $f_rel ;
28
31
29
- {
30
- no strict ' refs' ;
31
- no warnings ' redefine' ;
32
-
33
32
my $add_meth = " add_to_${meth} " ;
34
33
my $remove_meth = " remove_from_${meth} " ;
35
34
my $set_meth = " set_${meth} " ;
57
56
}
58
57
}
59
58
60
- $rel_attrs -> {alias } ||= $f_rel ;
61
-
59
+ my $qsub_attrs = {
60
+ ' $rel_attrs' => \{ alias => $f_rel , %{ $rel_attrs ||{} } },
61
+ ' $carp_unique' => \$cu ,
62
+ };
62
63
63
- my $rs_meth_name = join ' ::' , $class , $rs_meth ;
64
- *$rs_meth_name = subname $rs_meth_name , sub {
64
+ quote_sub " ${class} ::${rs_meth} " , sprintf ( <<'EOC' , $rel , $f_rel ), $qsub_attrs ;
65
65
66
66
# this little horror is there replicating a deprecation from
67
67
# within search_rs() itself
68
- shift -> search_related_rs($rel )
68
+ shift->search_related_rs( q{%1$s} )
69
69
->search_related_rs(
70
- $f_rel ,
70
+ q{%2$s} ,
71
71
undef,
72
72
( @_ > 1 and ref $_[-1] eq 'HASH' )
73
- ? { %$rel_attrs , %{ pop @_ } }
73
+ ? { %% $rel_attrs, % %{ pop @_ } }
74
74
: $rel_attrs
75
75
)->search_rs(@_)
76
76
;
77
-
78
- };
77
+ EOC
79
78
80
79
81
- my $meth_name = join ' ::' , $class , $meth ;
82
- *$meth_name = subname $meth_name , sub {
80
+ quote_sub " ${class} ::${meth} " , sprintf ( <<'EOC' , $rs_meth );
83
81
84
- DBIx::Class::_ENV_::ASSERT_NO_INTERNAL_WANTARRAY and my $sog = fail_on_internal_wantarray;
82
+ DBIx::Class::_ENV_::ASSERT_NO_INTERNAL_WANTARRAY and my $sog = DBIx::Class::_Util:: fail_on_internal_wantarray;
85
83
86
- my $rs = shift -> $rs_meth ( @_ );
84
+ my $rs = shift->%s ( @_ );
87
85
88
86
wantarray ? $rs->all : $rs;
89
-
90
- };
87
+ EOC
91
88
92
89
93
- my $add_meth_name = join ' ::' , $class , $add_meth ;
94
- *$add_meth_name = subname $add_meth_name , sub {
90
+ quote_sub " ${class} ::${add_meth} " , sprintf ( <<'EOC' , $add_meth , $rel , $f_rel ), $qsub_attrs ;
95
91
96
92
( @_ >= 2 and @_ <= 3 ) or $_[0]->throw_exception(
97
- " '$add_meth ' expects an object or hashref to link to, and an optional hashref of link data"
93
+ "'%1$s ' expects an object or hashref to link to, and an optional hashref of link data"
98
94
);
99
95
100
96
$_[0]->throw_exception(
101
- " The optional link data supplied to '$add_meth ' is not a hashref (it was previously ignored)"
97
+ "The optional link data supplied to '%1$s ' is not a hashref (it was previously ignored)"
102
98
) if $_[2] and ref $_[2] ne 'HASH';
103
99
104
100
my( $self, $far_obj ) = @_;
@@ -107,44 +103,43 @@ EOW
107
103
108
104
# the API needs is always expected to return the far object, possibly
109
105
# creating it in the process
110
- if ( not defined blessed $far_obj ) {
106
+ if( not defined Scalar::Util:: blessed( $far_obj ) ) {
111
107
112
108
$guard = $self->result_source->schema->storage->txn_scope_guard;
113
109
114
110
# reify the hash into an actual object
115
111
$far_obj = $self->result_source
116
- -> related_source( $rel )
117
- -> related_source( $f_rel )
112
+ ->related_source( q{%2$s} )
113
+ ->related_source( q{%3$s} )
118
114
->resultset
119
115
->search_rs( undef, $rel_attrs )
120
116
->find_or_create( $far_obj );
121
117
}
122
118
123
119
my $link = $self->new_related(
124
- $rel ,
120
+ q{%2$s} ,
125
121
$_[2] || {},
126
122
);
127
123
128
- $link -> set_from_related( $f_rel , $far_obj );
124
+ $link->set_from_related( q{%3$s} , $far_obj );
129
125
130
126
$link->insert();
131
127
132
128
$guard->commit if $guard;
133
129
134
130
$far_obj;
135
- };
131
+ EOC
136
132
137
133
138
- my $set_meth_name = join ' ::' , $class , $set_meth ;
139
- *$set_meth_name = subname $set_meth_name , sub {
134
+ quote_sub " ${class} ::${set_meth} " , sprintf ( <<'EOC' , $set_meth , $add_meth , $rel , $f_rel ), $qsub_attrs ;
140
135
141
136
my $self = shift;
142
137
143
138
my $set_to = ( ref $_[0] eq 'ARRAY' )
144
139
? ( shift @_ )
145
140
: do {
146
- carp_unique(
147
- " Calling '$set_meth ' with a list of items to link to is deprecated, use an arrayref instead"
141
+ $ carp_unique-> (
142
+ "Calling '%1$s ' with a list of items to link to is deprecated, use an arrayref instead"
148
143
);
149
144
150
145
# gobble up everything from @_ into a new arrayref
154
149
155
150
# make sure folks are not invoking a bizarre mix of deprecated and curent syntax
156
151
$self->throw_exception(
157
- " '$set_meth ' expects an arrayref of objects or hashrefs to link to, and an optional hashref of link data"
152
+ "'%1$s ' expects an arrayref of objects or hashrefs to link to, and an optional hashref of link data"
158
153
) if (
159
154
@_ > 1
160
155
or
@@ -170,35 +165,33 @@ EOW
170
165
# if there is a where clause in the attributes, ensure we only delete
171
166
# rows that are within the where restriction
172
167
$self->search_related(
173
- $rel ,
168
+ q{%3$s} ,
174
169
( $rel_attrs->{where}
175
- ? ( $rel_attrs -> {where }, { join => $f_rel } )
170
+ ? ( $rel_attrs->{where}, { join => q{%4$s} } )
176
171
: ()
177
172
)
178
173
)->delete;
179
174
180
175
# add in the set rel objects
181
- $self -> $add_meth (
176
+ $self->%2$s (
182
177
$_,
183
178
@_, # at this point @_ is either empty or contains a lone link-data hash
184
179
) for @$set_to;
185
180
186
181
$guard->commit if $guard;
187
- };
182
+ EOC
188
183
189
184
190
- my $remove_meth_name = join ' ::' , $class , $remove_meth ;
191
- *$remove_meth_name = subname $remove_meth_name , sub {
185
+ quote_sub " ${class} ::${remove_meth} " , sprintf ( <<'EOC' , $remove_meth , $rel , $f_rel );
192
186
193
- $_ [0]-> throw_exception(" '$remove_meth ' expects an object" )
194
- unless defined blessed $_ [1];
187
+ $_[0]->throw_exception("'%1$s ' expects an object")
188
+ unless defined Scalar::Util:: blessed( $_[1] ) ;
195
189
196
- $_ [0]-> search_related_rs( $rel )
197
- -> search_rs( $_ [1]-> ident_condition( $f_rel ), { join => $f_rel } )
190
+ $_[0]->search_related_rs( q{%2$s} )
191
+ ->search_rs( $_[1]->ident_condition( q{%3$s} ), { join => q{%3$s} } )
198
192
->delete;
199
- };
193
+ EOC
200
194
201
- }
202
195
}
203
196
204
197
1;
0 commit comments