[Dbix-class] Re: Use of ->resultset mandatory?
    Aaron Crane 
    dbix-class at aaroncrane.co.uk
       
    Tue Oct 31 09:47:24 GMT 2006
    
    
  
A. Pagaltzis writes:
>     my $glob = do { no strict "refs"; \*$_ };
>     *$glob = sub { ... };
> 
> The temporary seems unavoidable; apparently Perl’s grammar rules (or
> even its semantics) are non-orthogonal here, in that it won’t permit
> this:
> 
>     *{ do { no strict "refs"; \*$_ } } = sub { ... };
In the perls I've tried, you first get a warning about "Ambiguous use of
*{do{...}} resolved to *do{...}"; that suggests trying this version,
which does work:
  *{ (do { no strict "refs"; \*$_ }) } = sub { ... };
I personally find this clearer, even though it does require a temporary:
  for my $name (...) {
      my $code = sub { ... };
      no strict qw<refs>;
      *$name = $code;
  }
Or even:
  sub set_symbol {
      my ($name, $value) = @_;
      no strict qw<refs>;
      *$name = $code;
  }
  for my $name (...) {
      set_symbol($name, sub { ... });
  }
-- 
Aaron Crane
    
    
More information about the DBIx-Class
mailing list