Loading ...
Sorry, an error occurred while loading the content.

Re: [PBML] Why is @ISA not searched?

Expand Messages
  • merlyn@stonehenge.com
    ... Hans There is in the SYNOPSIS section of Exporter Hans package ModuleName; Hans require Exporter; Hans @ISA = qw(Exporter); Hans That is why the
    Message 1 of 13 , Dec 3, 2003
    • 0 Attachment
      >>>>> "Hans" == Hans Ginzel <hans@...> writes:

      Hans> There is in the SYNOPSIS section of Exporter

      Hans> package ModuleName;
      Hans> require Exporter;
      Hans> @ISA = qw(Exporter);

      Hans> That is why the Exporter::import() is used when module defines none.

      Because "use Foo qw(aaa bbb)" translates into:

      BEGIN {
      require Foo;
      Foo->import(qw(aaa bbb));
      }

      Note the method call there. Note that this means that Foo @ISA Exporter
      to define "import".

      --
      Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
      <merlyn@...> <URL:http://www.stonehenge.com/merlyn/>
      Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
      See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!
    • Jeff 'japhy' Pinyan
      ... The way Exporter works (in most cases) is like so: package Foo; require Exporter; @ISA = qw( Exporter ); # Foo is going to inherit Exporter s import()
      Message 2 of 13 , Dec 3, 2003
      • 0 Attachment
        On Dec 3, Hans Ginzel said:

        > I read allmost all perl* pages. I want to perfectly understand the
        >Eporter "different" mechanisms.
        >
        > There is in the SYNOPSIS section of Exporter
        >
        > package ModuleName;
        > require Exporter;
        > @ISA = qw(Exporter);
        >
        >That is why the Exporter::import() is used when module defines none.
        >But there are no "objects" (= noyhing is blessed()).

        The way Exporter works (in most cases) is like so:

        package Foo;
        require Exporter;
        @ISA = qw( Exporter ); # Foo is going to inherit Exporter's import()
        @EXPORT = qw( bar );
        sub bar { return "some string" }
        1;

        When you use Foo in a program with

        use Foo;

        what you're actually doing is saying

        # this happens at compile-time
        BEGIN {
        require Foo;
        Foo->import;
        }

        That is a CLASS METHOD call; Foo->import is calling Foo's 'import' method.
        As shown above, Foo inherits (an object oriented term) Exporter's 'import'
        method. When Foo->import happens, it calls the 'import' method with its
        first argument being 'Foo' (the name of the class invoking the method).
        This causes Exporter::import('Foo') to be called. The import method looks
        at its first argument, and get's that package's @EXPORT array, and then
        uses symbol aliasing to make an alias of the things (variables and
        functions) in @EXPORT in the CALLING package (the place where the 'use'
        occurred).

        So, if, in package 'main', we write 'use Foo', then the package Foo's
        'import' method is called. This actually calls Exporter::import('Foo'),
        which reads @Foo::EXPORT for a list of symbols to export to 'main'. The
        result is &main::bar is an alias for &Foo::bar.

        --
        Jeff "japhy" Pinyan japhy@... http://www.pobox.com/~japhy/
        RPI Acacia brother #734 http://www.perlmonks.org/ http://www.cpan.org/
        <stu> what does y/// stand for? <tenderpuss> why, yansliterate of course.
        [ I'm looking for programming work. If you like my work, let me know. ]
      • Hans Ginzel
        ... Oh, so. In the perldoc -f use there is: use Module LIST It is exactly equivalent to BEGIN { require Module; import Module LIST; } except that Module must
        Message 3 of 13 , Dec 3, 2003
        • 0 Attachment
          On Wed, Dec 03, 2003 at 07:25:19AM -0800, merlyn@... wrote:
          > Hans> @ISA = qw(Exporter);

          > Because "use Foo qw(aaa bbb)" translates into:
          > BEGIN {
          > require Foo;
          > Foo->import(qw(aaa bbb));
          > }

          Oh, so.

          In the perldoc -f use there is:

          use Module LIST

          It is exactly equivalent to

          BEGIN { require Module; import Module LIST; }

          except that Module must be a bareword.

          Half page later

          The "import" is not a builtin--it's just an
          ordinary static method call into the "Module"
          package to tell the module to import the list of
          features back into the current package. The mod-
          ule can implement its "import" method any way it
          likes, ...

          It would be good, if your above explanation would be
          in the perlfunc manual page.

          Relevant an interesting is also the second paragraph under
          "The Arrow Operator" in perlop. It sais, that Class->method()
          or PackageName->subroutine() respectively
          could be used "without blessing".


          Thank you

          Hans Ginzel
        • merlyn@stonehenge.com
          ... Hans It is exactly equivalent to Hans BEGIN { require Module; import Module LIST; } Hans except that Module must be a bareword. Hans Half page later
          Message 4 of 13 , Dec 4, 2003
          • 0 Attachment
            >>>>> "Hans" == Hans Ginzel <hans@...> writes:

            Hans> It is exactly equivalent to

            Hans> BEGIN { require Module; import Module LIST; }

            Hans> except that Module must be a bareword.

            Hans> Half page later

            Hans> The "import" is not a builtin--it's just an
            Hans> ordinary static method call into the "Module"
            Hans> package to tell the module to import the list of
            Hans> features back into the current package. The mod-
            Hans> ule can implement its "import" method any way it
            Hans> likes, ...

            Hans> It would be good, if your above explanation would be
            Hans> in the perlfunc manual page.

            Uh, where do you think I got what I said? It's identical. How
            is my explanation *not* on the manpage?

            --
            Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
            <merlyn@...> <URL:http://www.stonehenge.com/merlyn/>
            Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
            See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!
          • Hans Ginzel
            Hello, ... I did not say, that it is *not* in the manpage. I am saying, it could be there *better*. :-) Instaed of BEGIN { require Module; import Module LIST;
            Message 5 of 13 , Dec 4, 2003
            • 0 Attachment
              Hello,

              On Thu, Dec 04, 2003 at 03:48:15AM -0800, merlyn@... wrote:
              > > It would be good, if your above explanation would be
              > > in the perlfunc manual page.
              >
              > Uh, where do you think I got what I said? It's identical. How
              > is my explanation *not* on the manpage?

              I did not say, that it is *not* in the manpage. I am saying, it could
              be there *better*. :-)
              Instaed of

              BEGIN { require Module; import Module LIST; }

              on the top of perldoc -f use
              and 30 rows later _in the middle of the paragraph_

              The "import" is not a builtin--it's just an
              ordinary static method call into the "Module"
              package to tell the module to import the list of

              could be there your explanation

              BEGIN { require Module; Module->import Module LIST; }

              showing just from this line, that import is called form the Module,
              that @ISA mechanism is used because of '->'. The explanation sentence
              could be then ligthly modified.

              Thank you for your answers

              Hans Ginzel
              --
              This is perl, v5.8.0 built for i386-linux-thread-multi




              >
              > --
              > Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
              > <merlyn@...> <URL:http://www.stonehenge.com/merlyn/>
              > Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
              > See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!
              >
              >
              > Unsubscribing info is here: http://help.yahoo.com/help/us/groups/groups-32.html
              >
              > Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
              >

              --
              The Federal Judiciary's national IT infrastructure
              is migrated to a Linux/Intel platform
              http://www.businesswire.com/cgi-bin/f_headline.cgi?bw.111903/233235172&ticker=PECS
              Perl won the Linux Journal Editors' Choice Award :-)
              http://www.linuxjournal.com/article.php?sid=6868
              VIM is the Favorite Text Editor
              (Linux Journal Readers' Choice Awards) :-)
              http://www.linuxjournal.com/article.php?sid=7029
            • merlyn@stonehenge.com
              ... Hans I did not say, that it is *not* in the manpage. I am saying, Hans it could be there *better*. :-) You *do* realize that import Module LIST *is*
              Message 6 of 13 , Dec 4, 2003
              • 0 Attachment
                >>>>> "Hans" == Hans Ginzel <hans@...> writes:

                Hans> I did not say, that it is *not* in the manpage. I am saying,
                Hans> it could be there *better*. :-)

                You *do* realize that

                import Module LIST

                *is*

                Module->import(LIST)

                correct?

                That's why I'm saying it's *already* there. I didn't say *anything*
                that wasn't already in the manpage.

                --
                Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
                <merlyn@...> <URL:http://www.stonehenge.com/merlyn/>
                Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
                See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!
              • Hans Ginzel
                ... Thank you. So when I invoke the routine in a object way , the @ISA would be searched: main- routine(); I read also the perlobj page and found how to
                Message 7 of 13 , Dec 16, 2003
                • 0 Attachment
                  On Wed, Dec 03, 2003 at 03:31:12AM -0800, merlyn@... wrote:
                  > Hans> Why is the @ISA array not searched and/or the Bb::bb() not found?
                  > @ISA is for objects, not just a general subroutine search path.
                  > See "perldoc perlboot" for info on how to start with objects
                  > and how to use @ISA.

                  Thank you. So when I invoke the routine "in a object way", the @ISA would be searched:

                  main->routine();

                  I read also the perlobj page and found how to invoke routine from the
                  current package (class) without specifying the package name explicitly:

                  __PACKAGE__->routine();

                  For just invoking the parent's routine it should be
                  SUPER->routine();

                  Why does this not work:

                  { package BB;

                  sub bb { warn "bb" }
                  }

                  @ISA = qw(BB);

                  sub bb { warn "main" } # try to comment this line

                  __PACKAGE__->bb();

                  SUPER->bb();

                  Can't locate object method "bb" via package "SUPER" (perhaps you forgot
                  to load "SUPER"?) at o.pl line 12.

                  Also this does not work:

                  SUPER::bb(__PACKAGE__);

                  Undefined subroutine &SUPER::bb called at o.pl line 10.


                  Best regards
                  Hans Ginzel
                • Hans Ginzel
                  ... I got it: __PACKAGE__- SUPER::bb();
                  Message 8 of 13 , Dec 16, 2003
                  • 0 Attachment
                    On Tue, Dec 16, 2003 at 11:39:25AM +0100, hans wrote:
                    > For just invoking the parent's routine it should be
                    > SUPER->bb();
                    > Why does this not work:
                    > Can't locate object method "bb" via package "SUPER" (perhaps you forgot
                    > to load "SUPER"?) at o.pl line 12.

                    I got it:
                    __PACKAGE__->SUPER::bb();

                    > Hans Ginzel
                  Your message has been successfully submitted and would be delivered to recipients shortly.