Theo Lengyel > Tie-Silk-0.01_01 > Tie::Silk



Annotate this POD

Module Version: 0.01_01   Source  


Tie::Silk - Somewhat Intuitive List Knitter


  use Tie::Silk;
  tie %h, 'Tie::Silk';


 I wrote this module in order to manage several related lists that
were keyed off the same hash keys, but which store different data.
Therefore I can manage the available list elements by simply managing
the controlling hash (silk) and the results will cascade to all of the
content lists.

 this is a hash that also acts like a funny array. It preserves order
 like an array(akin to Tie::IxHash), but also has some other specific
 behavior that is described below ( the `===' I am using here to mean
 `equivalent to')
   where $x is an integer $x >= 0
        then $h{$x} === $h{$h{"-$x"}}

 here is a sample hash:
 $th = tie %h, 'Tie::Silk';
 %h = qw( _foo  bar
          _baz  fup

 Tie::Silk; these are the behaviors we are after:
 1) when accessed with a negative number it returns the hash hey for
    the indicated pair(need to be careful with a `minus zero' key
    MUST be a string because perl compiler will convert an unquoted -0 to 0)
      $h{'-0'}   === _foo
      $h{-1}     === _baz

 2)  when accessed with a positive integer it returns the value for
     the associated key pair (same as fetching it with the normal
     hash key, but now we are accessing it with array-like indexing 
     using {} instead of [] notation)
      $h{0}      === bar  === $h{_foo} === $h{$h{'-0'}}
      $h{1}      === fup  === $h{_baz} === $h{$h{-1}}
      $h{_baz}   === fup
      $h{_foo}   === bar
 3) a normal hash key preceded by a `-' (minus sign) returns the
    index of that pair ( except when setting a value this way, see #4)
      $h{-_baz}  === 1
      $h{-_foo}  === 0

 4) when setting an element and preceding the hash key with a minus
    sign `-' this actually replaces the hash key with the value
    therefore we have:
      $h{-_foo}  = '_new_foo' === $h{'-0'}
      $h{_new_foo}  === bar
      $h{-_new_foo} === 0
      $h{'-0'}      === _new_foo

 5) you cannot set a new slot with an integer unless the integer
    matches the next open slot, otherwise confusion may ensue


None by default.




  Better documentation, better examples


Theo Lengyel, <<gt>


Tie::Strand perl Tie::IxHash

syntax highlighting: