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

Hi, I am looking for something with the exact functionality of aliased::factory:
  1. ability to refer to perl Classes with shortened names
  2. on demand-loading of Classes when referred to
However, there are issues with this module on win32 that I can attest to, having tried it. So something with this exact functionality that works is desired. aliased and namespace dont offer the 2nd feature I'm looking for. In the meantime, I will try to see what is biting aliased::factory.



The mantra of every experienced web application developer is the same: thou shalt separate business logic from display. Ironically, almost all template engines allow violation of this separation principle, which is the very impetus for HTML template engine development.

-- Terence Parr, "Enforcing Strict Model View Separation in Template Engines"

Replies are listed 'Best First'.
Re: Package shortener and loader
by MidLifeXis (Monsignor) on Jun 24, 2011 at 15:06 UTC

    According to the error report, I would guess that a regular expression is not being escaped properly. It appears that a number prefixed by a backslash is causing it problems (see the '\5 <-- HERE' in test output) around line 60 of aliased::factory. This is also supported by the large numbers of passes on *nix and failures on Windows.

    In fact, the error appears to be in the line

    ($err = $@) =~ s/ at $f line \d+\.\n//;

    I believe that it should be (untested)

    ($err = $@) =~ s/ at \Q$f\E line \d+\.\n//;

    Update: Had \Q and \E reversed. perlre

    Update2: Bug report submitted.

    A test should probably be written (if possible) to reproduce this as part of the patch package. HTH.

    --MidLifeXis

      I concur. If you see this, it's a problem with a *test*, not the *module*, and you can safely force the install.

        Please correct me if I am wrong, but it seems to me (although I am not currently developing on windows), that under windows, if the module fails to require a module being requested, and the value of __FILE__ contains something matching \\\d, that the application will exhibit the same behavior as the test.

        The error is caused by passing an unescaped filename as a pattern, and it is not being caught by tests on *nix, because the value for __FILE__ does not contain '\'. I think that there are two parts to the fix - one is to enhance the test to enable the dev to test windows filenames on unix (is it worth it? not sure), and the other is to ignore the backslashes in the generated pattern so it does not happen outside of testing.

        However, I do concur, that with appropriate testing of your application, and appropriate controls in production, that you will probably be safe forcing the install. You can get uncaught errors however, if the module being required errors out for some reason.

        --MidLifeXis

Re: Package shortener and loader
by metaperl (Curate) on Jun 24, 2011 at 15:14 UTC