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

Re: redefinition warnings

Expand Messages
  • Joshua Chamas
    ... Yeah, you are an old timer all right. Welcome to the club. :) ... I implemented the buzzword because I figured there would be greater acceptance of the
    Message 1 of 4 , Mar 15, 2002
    • 0 Attachment
      > "Weyer, Jens" wrote:
      >
      > Hello !
      >
      > First of all I would like to introduce myself, because i am new to this mailinglist.
      > My name is Jens, i am living in Germany and i am 24 years old.
      > I've been working with Linux, Perl, HTML and all the stuff around since 1996,
      > so I would suppose, that I am not new to the internet-djungle :-)
      >

      Yeah, you are an old timer all right. Welcome to the club. :)

      > Nevertheless - we did not want to swap our Linuxserver with a m$ IIS...
      > We could arrange it, that we can keep our Server on running as it is, but
      > we still had to use ASP... So I found the Apache::ASP project.
      >

      I implemented the buzzword because I figured there would be greater
      acceptance of the platform as a technology. Thanks for the validation
      of the approach. & between Apache::ASP & Linux, I could not ask for
      a nicer web dev enviroment.

      > Now there is a huge problem: We have an ASP file for every page on
      > that server, and in each file exists the same subs like
      > Write_Content_HTML() and so on. We include there the main content
      > of each webpage dynamically. There are more such subs, but one should

      I think it is bad form to define subroutines in ASP scripts.
      However, like you found, setting UniquePackages to 1 can make
      it so that redefinition warning go away. But then you no longer
      have the global namespace to work with, so right your code stops
      working that was relying on this.

      You should find some way to share your subroutines ideally.
      One easy was to do this is to put them all in the global.asa
      file, and pass parameters to them to change their behavior
      on a per script basis. Another thing to try is to decomp
      your application logic into a global object with methods.
      You can set the global object in global.asa like:

      == httpd.conf
      PerlSetVar UseStrict 1

      == global.asa
      use vars qw($Object);
      sub Script_OnStart {
      $Object = Object->new();
      }

      Then you can call in each script:

      <% $Object->Write_Content_HTML(); %>

      Depending on the $Object state, your method call might change
      its behavior, so you can tailor the method execution on
      a per script basis that way too. Sometimes objects are
      better for state control, than passing parameters.

      A more concrete script example might suggest better what
      approach might work here if the above didn't help enough.

      --Josh
      _________________________________________________________________
      Joshua Chamas Chamas Enterprises Inc.
      NodeWorks Founder Huntington Beach, CA USA
      http://www.nodeworks.com 1-714-625-4051

      ---------------------------------------------------------------------
      To unsubscribe, e-mail: asp-unsubscribe@...
      For additional commands, e-mail: asp-help@...
    • Joshua Chamas
      ... Hey Jens, I am glad to hear that moving the subs to global.asa is working out. If there are just too many subs like this after a while & your global.asa
      Message 2 of 4 , Mar 15, 2002
      • 0 Attachment
        Joshua Chamas wrote:
        >
        > You should find some way to share your subroutines ideally.
        > One easy was to do this is to put them all in the global.asa
        > file, and pass parameters to them to change their behavior
        > on a per script basis. Another thing to try is to decomp
        > your application logic into a global object with methods.
        > You can set the global object in global.asa like:
        >

        Hey Jens,

        I am glad to hear that moving the subs to global.asa is working out.
        If there are just too many subs like this after a while & your
        global.asa gets too messy, consider using the GlobalPackage config
        so that you can have a separate perl module for these subs like this:

        == httpd.conf
        PerlSetVar GlobalPackage My::Site

        == perllib/My/Site.pm
        sub first {}
        sub second {}

        Since all ASP scripts will now be compiled into the My::Site package,
        everything defined in that package, just like the global.asa
        can be globally shared across all your ASP scripts. Note you still
        need to keep ASP event handlers like Script_OnStart in global.asa
        even if you have a separate package like this, but using this
        approach helps keep ASP centric event handlers separate from
        your other misc subroutines.

        --Josh
        _________________________________________________________________
        Joshua Chamas Chamas Enterprises Inc.
        NodeWorks Founder Huntington Beach, CA USA
        http://www.nodeworks.com 1-714-625-4051

        ---------------------------------------------------------------------
        To unsubscribe, e-mail: asp-unsubscribe@...
        For additional commands, e-mail: asp-help@...
      • Ellers
        ... I m not sure if it helps in your situation, but I sometimes find it useful to treat ASP s Include facility as a kind of subroutine substitute. That is,
        Message 3 of 4 , Mar 17, 2002
        • 0 Attachment
          >
          >Now there is a huge problem: We have an ASP file for every page on
          >that server, and in each file exists the same subs like
          >Write_Content_HTML() and so on. We include there the main content
          >of each webpage dynamically. There are more such subs, but one should
          >be enough to explain the problem.
          >The code works fine, but the error_logs are full of redefinition warnings,
          >due to the fact, that the same subs are used in each ASP file.

          I'm not sure if it helps in your situation, but I sometimes find it
          useful to treat ASP's Include facility as a kind of subroutine
          substitute.

          That is, instead of:

          $result = do_something( 'arg1', $arg2 );

          sub do_something
          {
          my ( $first, $second ) = @_;
          ...
          return 1;
          }


          I do:

          $result = $Response->Include( 'my_sub_do_something.asp', 'arg1', $arg2 );

          [my_sub_do_something.asp]

          <%
          my ( $first, $second ) = @;

          ...

          return 1;
          %>



          I appreciate not everyones needs are the same as mine - and the above
          doesn't eliminate using packages and the global.asa, but sometimes
          I've found it useful.


          HTH
          Ellers


          ---------------------------------------------------------------------
          To unsubscribe, e-mail: asp-unsubscribe@...
          For additional commands, e-mail: asp-help@...
        Your message has been successfully submitted and would be delivered to recipients shortly.