Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I understand a call to new from perl classes, but I see the following code for perl packages
use Dir::Pkg; my $m = Dir::Pkg->new();

I do not see a 'new' defined in the package.

How does this work? Thanks

Replies are listed 'Best First'.
Re: package new
by choroba (Cardinal) on May 30, 2013 at 07:17 UTC
    You have not included the source of Dir/Pkg.pm. Without it, we can just
    use Crystal::Ball;
    لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ
      This is just the module I've been looking for. Thanks!
      oops! I meant to say the code was simply an example and not actual code. What I wanted to ask was if the package had to have 'new' defined.
Re: package new
by james2vegas (Chaplain) on May 30, 2013 at 07:45 UTC
    use ESP;
    new is probably being created by something like Moose, Moo (an OO framework), or something declared to be the superclass of Dir::Pkg with parent or base (or maybe @ISA).
      The package code looks like the following:
      package Dir::Pkg; use strict; use vars qw(@ISA @EXPORT @EXPORT_OK $VERSION); require Exporter; @ISA = qw(Exporter); @EXPORT = qw(sub1 sub2); $VERSION = 1.00; use SomeOtherModule; sub1 { } sub2 { }

      I cannot see any other sub classing. Let me check if I am missing something.

      Thanks

Re: package new
by BrowserUk (Patriarch) on May 30, 2013 at 13:36 UTC

    A simple way to discover this for yourself. Install Devel::Trace. Then run:

    perl -d:Trace -MDir::Pkg -E"Dir::Pkg->new()"

    With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.
      I will try that. Thanks
Re: package new
by Anonymous Monk on May 30, 2013 at 16:41 UTC

    My apologies. I was looking at the wrong version of the .pm

    I did learn a bit from this exercise though. Thanks