Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: Understanding a OOP Code: Package declared within a Package

by BrowserUk (Patriarch)
on Oct 06, 2016 at 12:14 UTC ( #1173396=note: print w/replies, xml ) Need Help??


in reply to Understanding a OOP Code: Package declared within a Package

In the Code , I found , a (actually more then one) Package, being declared in another Package.

I assume by that you mean you have a file with more that one package statement in it; and those package statements have different names after them?

Functions and methods become a part of whatever package is currently in force. So in this snippet:

package A; sub fred { ... } package B; sub bill { ... } package C; sub mary { ... } package B; sub joan{ ... } package A; sub cleo{ ... }

There are five functions declared in three packages: A::fred() & A::cleo(); B::bill()/c> & <c>B::joan(); C::mary()

The number and ordering of package statement within a file is completely flexible; a subroutine belongs to whatever package (statement) is in force at the time of its definition.

It is also quite possible to split packages across multiple files; though the are generally less good reasons for doing so.


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". I knew I was on the right track :)
In the absence of evidence, opinion is indistinguishable from prejudice.

Replies are listed 'Best First'.
Re^2: Understanding a OOP Code: Package declared within a Package
by sachinz2 (Acolyte) on Oct 06, 2016 at 12:29 UTC
    Hi

    No Not like that, What I have is like this,

    Package A::B::C;

    1;

    Package A::B::D;

    sub abc {..... ... }

    sub xyz { ......... }

    Package A::B::E

    sub new{ ..... }

    Package A::B::F

    use base (A::B::E);

    Packge A::B::G

    use base (A::B::E);

      The same basics apply.

      The number of elements in the name doesn't matter, it is still just a name.

      Any 'relationship' between packages with the same prefix is implied -- for human consumption only -- they are entirely independent as far as Perl is concerned.

      Those packages with the statement use Base (X::Y::Z) at the top, are subclasses of the named package, which does define an OO relationship between them, such that the subclassing package (those with use Base ...), inherit (or overide) all the code (functions/methods) from the named base package.


      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". I knew I was on the right track :)
      In the absence of evidence, opinion is indistinguishable from prejudice.

      This looks like it might just be done for organization or structural purposes, or perhaps to save memory if A::B would be a huge module to load. It should be possible to just have a "Package A::B" at the top without having to specify ::C-F, I might be wrong though.

      Check out this page, specifically the "Naming of modules" section.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1173396]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (8)
As of 2023-12-06 10:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What's your preferred 'use VERSION' for new CPAN modules in 2023?











    Results (30 votes). Check out past polls.

    Notices?