in reply to Perl Inheritance Not Working as Expected

If you check the new in the FakeTuple it's using the one arg'd version of bless which as noted in the documentation for same isn't inheritable. The constructor should be using the package used to call it and the two arg bless $ref, $class form.

The cake is a lie.
The cake is a lie.
The cake is a lie.

Replies are listed 'Best First'.
Re^2: Perl Inheritance Not Working as Expected
by InfiniteSilence (Curate) on Apr 28, 2026 at 19:49 UTC

    This error is just too easy to make. I used to use h2xs but it creates so much stuff that I avoid using it. I was at a Perl conference where one of the Stonehenge presenters used a 'new' tool to create classes but I forgot what it was.

    h2xs -AXn Goo Defaulting to backwards compatibility with perl 5.40.1 If you intend this module to be compatible with earlier perl versions, + please specify a minimum perl version with the -b option. Writing Goo/lib/Goo.pm Writing Goo/Makefile.PL Writing Goo/README Writing Goo/t/Goo.t Writing Goo/Changes Writing Goo/MANIFEST joel@PLANTER1 goo]$

    This does not create a 'new' boilerplate for you...

    ... our $VERSION = '0.01'; # Preloaded methods go here. ...

    Other stuff but no 'new'. A new() method in the preferred fashion would be good, no?

    Celebrate Intellectual Diversity

      I create OO modules manually. The boilerplate is minimal. FWIW, I use module-starter --module='XXX:XXX' --builder='ExtUtils::MakeMaker' --author='XXX' --email='XXX' to start a new module and never sought any alternative.

      Other stuff but no 'new'. A new() method in the preferred fashion would be good, no?

      No, because:

      1. Not every module is a class.
      2. Some (most?) modules which are classes use a framework which provides a standard new() in the superclass.

      If you only ever write OO modules and know that these will always have their own new() method then you can use one of the very many templating engines to write your own module creator to achieve this. I'm sure most of the existing new-project-creation tools have hooks for customisation too but I've never been bothered enough to go looking, TBH.


      🦛