return ();
}
+sub FETCH_CODE_ATTRIBUTES {
+ my ($class,$code) = @_;
+ @{ $class->_attr_cache->{$code} || [] }
+}
+
sub _attr_cache {
my $self = shift;
my $cache = $self->can('__attr_cache') ? $self->__attr_cache : {};
use constant UNRESOLVABLE_CONDITION => \ '1 = 0';
BEGIN {
+ # add preliminary attribute support
+ # FIXME FIXME FIXME
+ # To be revisited when Moo with proper attr support ships
Sub::Quote->VERSION(2.002);
+ require attributes;
}
# Override forcing no_defer, and adding naming consistency checks
sub quote_sub {
};
my $cref = Sub::Quote::quote_sub( $_[0], $_[1], $_[2]||{}, $sq_opts );
+
+ # FIXME FIXME FIXME
+ # To be revisited when Moo with proper attr support ships
+ if(
+ # external application does not work on things like :prototype(...), :lvalue, etc
+ my @attrs = grep {
+ $_ !~ /^[a-z]/
+ or
+ Carp::confess( "The DBIC sub_quote override does not support applying of reserved attribute '$_'" )
+ } @{ $sq_opts->{attributes} || []}
+ ) {
+ Carp::confess( "The DBIC sub_quote override does not allow mixing 'attributes' with 'no_install'" )
+ if $sq_opts->{no_install};
+
+ # might be different from $sq_opts->{package};
+ my ($install_into) = $_[0] =~ /(.+)::[^:]+$/;
+
+ attributes->import( $install_into, $cref, @attrs );
+ }
+
+ $cref;
}
sub sigwarn_silencer ($) {
}
;
+### Test the upcoming attributes support
+require DBIx::Class;
+@DBICTest::QSUB::ISA = 'DBIx::Class';
+
+my $var = \42;
+my $s = quote_sub(
+ 'DBICTest::QSUB::attr',
+ '$v',
+ { '$v' => $var },
+ {
+ # use grandfathered 'ResultSet' attribute for starters
+ attributes => [qw( ResultSet )],
+ package => 'DBICTest::QSUB',
+ },
+);
+
+is $s, \&DBICTest::QSUB::attr, 'Same cref installed';
+
+is DBICTest::QSUB::attr(), 42, 'Sub properly installed and callable';
+
+is_deeply
+ [ attributes::get( $s ) ],
+ [ 'ResultSet' ],
+ 'Attribute installed',
+unless $^V =~ /c/; # FIXME work around https://github.com/perl11/cperl/issues/147
+
done_testing;