develooper Front page | perl.perl5.porters | Postings from June 2017

lib/_charnames.pm puts references in %^H

Thread Next
From:
Paul "LeoNerd" Evans
Date:
June 14, 2017 16:44
Subject:
lib/_charnames.pm puts references in %^H
Message ID:
20170614174351.03555adb@shy.leonerd.org.uk
I've started investigating the "false-positives" I get out of my
attempt to warn on stringifying references, and so far every one has
turned out to be a real bug in other code :) Go me.

In one case,

  lib/_charnames.pm lines 627-630:

  627   $^H{charnames} = \&charnames ; 
  628   $^H{charnames_ord_aliases} = {};
  629   $^H{charnames_name_aliases} = {};
  630   $^H{charnames_inverse_ords} = {};

You would think that this can't work, given as perlvar says, on the
subject of %^H:

  All the entries are stringified when accessed at runtime, so only
  simple values can be accommodated.  This means no pointers to
  objects, for example.

Except its wording here isn't quite right. What %^H does is that values
are stringified at the point when compilation is over and runtime (for
that block) starts.

I suspect what _charnames.pm is doing here is that these values are
being used only during compilation of the containing block, and once
runtime happens they get stringified and would no longer work, only
that's OK because they won't get called upon again.

If this is the case: does anyone have any suggestions on how I might
stop it triggering a warning from my code? I feel that _charnames.pm
is doing something slightly naughty here, that perl happens to let it
get away with. My added warning then highlights it doing that.

Additionally: maybe, regardless of my 'use warnings qw( stringify );'
work, that stringification of references stored in %^H ought to cause a
warning anyway, because otherwise that's quite subtle. Also maybe then
the warning could have clearer text; perhaps something like

  Stringifying a reference to CODE at end of compilation phase at ...

instead of how it appears now, as

  Stringifying a reference to CODE at ../lib/_charnames.pm line 627.

-- 
Paul "LeoNerd" Evans

leonerd@leonerd.org.uk      |  https://metacpan.org/author/PEVANS
http://www.leonerd.org.uk/  |  https://www.tindie.com/stores/leonerd/

Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About