Dear Monks

I am sure many of you use the Class::Accessor module in one way or another, I have a little issue

I need to be able to dump a object to a hash, so each accessor created by Class::Accessor I want a key in the hash... hope that makes sense. Issue is I am not sure how to go about getting this data ? I am sure its there in plain sight but I cant seem to work it out....The code which creates the accessor is..

sub mk_accessors { my($self, @fields) = @_; $self->_mk_accessors('rw', @fields); } { no strict 'refs'; sub _mk_accessors { my($self, $access, @fields) = @_; my $class = ref $self || $self; my $ra = $access eq 'rw' || $access eq 'ro'; my $wa = $access eq 'rw' || $access eq 'wo'; foreach my $field (@fields) { my $accessor_name = $self->accessor_name_for($field); my $mutator_name = $self->mutator_name_for($field); if( $accessor_name eq 'DESTROY' or $mutator_name eq 'DESTR +OY' ) { $self->_carp("Having a data accessor named DESTROY in + '$class' is unwise."); } if ($accessor_name eq $mutator_name) { my $accessor; if ($ra && $wa) { $accessor = $self->make_accessor($field); } elsif ($ra) { $accessor = $self->make_ro_accessor($field); } else { $accessor = $self->make_wo_accessor($field); } unless (defined &{"${class}::$accessor_name"}) { *{"${class}::$accessor_name"} = $accessor; } if ($accessor_name eq $field) { # the old behaviour my $alias = "_${field}_accessor"; *{"${class}::$alias"} = $accessor unless defined & +{"${class}::$alias"}; } } else { if ($ra and not defined &{"${class}::$accessor_name"}) + { *{"${class}::$accessor_name"} = $self->make_ro_acc +essor($field); } if ($wa and not defined &{"${class}::$mutator_name"}) +{ *{"${class}::$mutator_name"} = $self->make_wo_acce +ssor($field); } } } }

Any ideas would be welcome ?


In reply to Inside Class::Accessor by ropey

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.