Dear Monks,

I thought I understood how SUPER works - but today I tried to override a method in a CDBI object, and things didn't happen as I expected.

I have a My::User.pm, which (among other columns), has a Password column. Since I'm hashing the password, I wanted to able to call $u->password("secret"), and have it stored in the database automatically hashed. So in my User.pm module, I tried to override the password method:

sub password { my $self = shift; if (@_) { # we're setting a value $_[0] = Digest::MD5::md5_base64($_[0]); } return $self->SUPER::password(@_); }

But when I try this, I get the following error:

Can't locate object method "password" via package "My::User" at My/Use +r.pm line 37.

So I have two questions:

  1. What am I doing wrong with the SUPER call?
  2. I'm sure this can be done with triggers - is "before_set_password" the only one I need to set?

Thanks!

-- zigdon


In reply to (z) SUPER and Class::DBI by zigdon

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.