Yes, if I undestand you correctly :>) I paste a piece of my code here, which demonstrates the object and tied hash simultaneously.
package XML::Trivial::Element; use Scalar::Util 'weaken'; use strict; use warnings; sub new { my ($class, $aref, $nsstack) = @_; tie my %h, $class, $aref || [], $nsstack; my $self = bless \%h, $class; my %ehns; my $key; my $s = tied(%$self); foreach (@{$s->{ea}}) { tied(%$_)->{parent} = $self; weaken(tied(%$_)->{parent});#because it is circular ref $key = $_->ns(undef).'*'.$_->ln(); $ehns{$key} = $_ unless exists $ehns{$key}; } $s->{ehns} = \%ehns; return $self; } sub TIEHASH { my ($class, $a, $nsstack) = @_; #$a is arrayref like [name, atts, type1, data1, type2, data2, ...] my @ea; my %eh;#elements my @ta; #texts my @ca; #cdatas my @pa; my %ph;#process instructions my @na; #notes my $firstkey; my $lastkey; my %next; my %nh; #hash of namespaces in scope foreach (@$nsstack) { while (my ($name, $value) = each %$_) { $nh{$name} = $value; } } for (my $i = 0; $i < @$a; $i += 2) { #too much code here } return bless {a=>$a, ea=>\@ea, eh=>\%eh, ta=>\@ta, ca=>\@ca, pa=>\@pa, ph=>\%ph, na=>\@na, nh=>\%nh, parent=>undef, firstkey=>$firstkey, next=>\%next }, $class; } sub FETCH { my ($self, $key) = @_; $key =~ /^\d+$/ and return $$self{ea}[$key]; $key =~ /\*/ and return $$self{ehns}{$key}; return $$self{eh}{$key}; } sub EXISTS { my ($self, $key) = @_; $key =~ /\*/ and return exists $$self{ehns}{$key}; return exists $$self{eh}{$key}; } sub FIRSTKEY { return $$_[0]{firstkey}; } sub NEXTKEY { return $$_[0]{next}{$$_[1]}; } sub SCALAR { return $$_[0]{a}[0]; } #this is object method sub p { #parent my ($self) = @_; return tied(%$self)->{parent}; }

In reply to Re: Tying objects by pajout
in thread Tying objects by Alien

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.