in reply to Re: ?Re: Generic Composite Interface
in thread Generic Composite Interface

This is your problem here:
my $logger = ${loggertyp}->new();
If you're gonna call new, you're gonna have to ensure that the package is loaded. See how the LWP moudules do it for the various protocol handlers. It's a mere matter of coding up a proper require dynamically. No big deal, but you have to do it, true.

Or, you can add something like the following subroutine (untested):

sub UNIVERSAL::AUTOLOAD { my ($pack, $meth) = $AUTOLOAD =~ /(.*)::(.*)/; die "do you really want me to pull in $pack for $meth?\n" unless $me +th eq "new"; eval "require $pack"; die $@ if $@; die "$pack didn't define $meth" unless defined &$AUTOLOAD; goto &$AUTOLOAD; }

-- Randal L. Schwartz, Perl hacker

Replies are listed 'Best First'.
Re: ?Re: Re: ?Re: Generic Composite Interface
by chhe (Sexton) on Mar 24, 2002 at 17:41 UTC

    Thanx, i think got it:

    With UNIVERSAL::AUTOLOAD one can intercept calls to a perl object, which have failed

    With "require" one can dynamically "use" modules, depending for example on some input, like in my case reading the Objectname from the input

    Really neat stuff, but i agree that most application would'nt want or need to use this stuff...

    I wonder, how perl compares here with other languages....

    But anyway, thanx for the help

    Chris
      Really neat stuff, but i agree that most application would'nt want or need to use this stuff...
      I wonder, how perl compares here with other languages....
      In what way are you comparing Perl with other languages? In that most applications won't need dynamic dispatch, dynamic code loading, huge amounts of introspection?

      Or in Perl's need to use such tricks? Or that Perl can in fact do such tricks? Or that Perl has a different sort of ratio of programs that need such tricks to those that don't? And would that be less, or more?

      Please narrow the boundaries of your desire for comparison. {grin}

      -- Randal L. Schwartz, Perl hacker

        You caught me again, i really have to be more precise in what i am trying to say.... maybe i'll blame it on the fact, that i mostly communicate in other languages then english...:-)....

        I meant to say is that what i like about perl, that you can have it all: that's it is really "multi-paradigm". You can have dynamic dispatch, dynamic code loading and introspection for free, when you need it and granted you know how to do it ... {smile}. I do not see these features as tricks, granted the user is aware of the consequences and trade-offs of using them, i see them as strenght of the language. If you don't really need them, then you'll be more specific and leave them away. And that's where i was wondering about other languages, like i know a little C++: There certainly you have type safety, you have type-safe dynamic dispatch, more general dynamic dispatch aka Smalltalk? Quite a coding effort!? I think Coplien did some work on that...? Dynamic loading and selection of classes at runtime? Not impossible but, quite a effort!? And that's where i was thinking, how do the languages, Perl, C++, maybe also Java and some other scripting languages, compare with regard to supporting these features, to what extent, what does it mean in terms off effort to achieve these features, how would one achieve these features, what are trade-offs and maybe also the rationale behind how these features are supported or not.....? Does this make any sense?.... Maybe i am just hopelessly behind, and these things have been answered with things like "component" technology etc? But i tend to like to keep things small and simple.....