in reply to Re^2: How to completely destroy class attributes with Test::Most?
in thread How to completely destroy class attributes with Test::Most?

The chained SUPER::add_resources calls are fine, but why are you overriding new if all you do is return $class->SUPER::new()? I suggest replacing your "empty" new methods with comments indicating that new is inherited.

Why are all of your instance variables prefixed with underscore? They are instance variables — of course they are internal — so an underscore prefix is just extra typing for no reason.

Baseline Perl 5 OO is really simple: an object is a reference that has been blessed with a vtable. A vtable is a package stash, which bless looks up from the package name. A method call is performed by looking for that method in the vtable. If found, it is called. If not found, the @ISA array is checked and any packages listed there are searched recursively for the method, which is called if found, otherwise AUTOLOAD is tried similarly. If none of this produces a code reference, a fatal exception is thrown. While calling a method, whatever was used to start the method search is unshifted onto @_.

All the rest is built on those basic mechanisms. These is nothing magic about my $self = shift; at all.

Replies are listed 'Best First'.
Re^4: How to completely destroy class attributes with Test::Most?
by nysus (Parson) on Aug 26, 2019 at 03:57 UTC

    Thanks for the extra tips and advice. The code is a work and progress and still kind of crufty. The new constructors, for example, used to have code in them until I figured out how write the code more cleanly. I just haven't bothered to remove them yet.

    Regarding underscores, are you saying that because they are *all* internal, there is no need to bother with the convention of using them?

    $PM = "Perl Monk's";
    $MCF = "Most Clueless Friar Abbot Bishop Pontiff Deacon Curate Priest Vicar";
    $nysus = $PM . ' ' . $MCF;
    Click here if you love Perl Monks

      For instance variables, that is, the keys in the blessed anonymous hash that you are using to store your instance data, a leading underscore more usefully indicates "private from subclasses" since all of an object's implementation is supposed to be encapsulated behind methods. So there is a convention, but it is a different convention from method names, where the leading underscore indicates that a method is not part of the external API.

        OK, I think I got you. So since my chained classes basically all work together to essentially create one object across many classes, there really is not need to flag them as private from one class to another.

        $PM = "Perl Monk's";
        $MCF = "Most Clueless Friar Abbot Bishop Pontiff Deacon Curate Priest Vicar";
        $nysus = $PM . ' ' . $MCF;
        Click here if you love Perl Monks