Dearest Monks,

I am trying to get some more common sense to a class, instance of TK MainWindow that I have taken over the maintenance of. Downside is this class has more than 3000! lines of code and wildely assigns key value pairs to its own blessed hash. Some of these are actually accessed or created (exclusively) outside the actual class.

Okay enough description of the desaster. How do I sort this. My so far best guess was to lock keys using Hash::Util and create the following code for actually used hash keys:

use Hash::Util qw/lock_keys/; my $self = $classname->SUPER::new( %options ); # Tk keys ||= in order to not overwrite already initialized keys $self->{ _ClassInit_ } ||= undef; $self->{ _Destroy } ||= undef; $self->{ _names_ } ||= undef; $self->{ _TkValue_ } ||= undef; $self->{ _XEvent_ } ||= undef; $self->{ __Images__ } ||= undef; # Local elements - those have not been defined yet $self->{ MyKey1 } = undef; $self->{ MyKey2 } = undef; lock_keys( %{ $self } );
This works fine. I have used it successfully for the last 2 days and reduced the number of required non Tk keys to about half their original number plus know what is going on. However in come cases I still discover new keys which are created only when certain expections are thrown or errors occur and depend on the used input data or user interaction. I would therefore like to create a hash wrapper that preferably reports the "caller" and the key whenever a key is added or deleted. In a few weeks I would look at a log file and dive into investigation of those last remnants of 'really really really' bad code. Can anyone point me to a place where I can see how to do this?


Cheers,
PerlingTheUK

In reply to Monitoring a Blessed Hash by PerlingTheUK

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.