> "Sharad Gupta" <[EMAIL PROTECTED]> wrote in message
>news:[EMAIL PROTECTED]
> Hi All,
>
> I am really tired now:
>
> --------------------------------------
> package Foo;
>
> use strict;
> use LWP::UserAgent;
>
>
> sub new {
> return bless {},shift;
> }
>
>
> sub Foo::INC {
> my ($self,$filename) = @_;
> my @paths = "http:/me.com";
> my @urls = map{$_ . "/" . [EMAIL PROTECTED];
> my $ua = LWP::UserAgent->new();
> foreach my $url(@urls) {
> my $request    = HTTP::Request->new($url);
> my $response = $ua->request($request);
> if($response->is_success()) {
> return $response->content();
> }
> }
> return undef;
> }
> --------------------------------------
>
>
> What i am trying to do is hook into the @INC so that i can find the
modules via http, but a simple test like:
>
> --------------
> #!/usr/local/bin/perl
>
> BEGIN { push @INC,Foo->new() }
> use Bar;
> -------------
>
> Cannot find Bar.pm.
>
>
> Any ideas??.

interesting. without you providing much background information, purpose
(actually you did say you are trying to hook into @INC but i don't really
know what you mean by that), etc, i can only guess that you are trying to
build, compile and include some other modules when your users say "use Foo".
below is a toy program that hopefully will get you closer to what you need:

package Foo;

END{ unlink @ms }

our @ms;

sub new{
 return bless {} => shift;
}

sub hi{
 print "hi\n";
}

#--
#-- dynamicly build and include whatever modules the users requested
#--
sub import{

 my $class  = shift;

 for(@_){

  open(NM,">$_.pm") || die $!;

  push(@ms, "$_.pm");

  print NM qq/
   package $_;
   sub new{
    return {} => shift;
   }
   sub $_\_say_hi{
    print "$_ says hi\\n";
   }
   1;
   /;

  close(NM);

  require "$_.pm";
 }
}

1;

__END__

a driver:

#!/usr/bin/perl -w
use strict;

#--
#-- Foo.pm builds Bar.pm and Ber.pm and Bee.pm and use it
#-- in fact, you can put as many module names here and Foo.pm will build it
for you
#--
use Foo qw(Bar Ber Bee);

my $f = Foo->new; $f->hi;

#--
#-- no need to 'use Bar' or 'use Ber' or 'use Bee' because Foo.pm does that
for us per request
#--
my $bar = Bar->new; $bar->Bar_say_hi;
my $ber = Ber->new; $ber->Ber_say_hi;
my $bee = Bee->new; $bee->Bee_say_hi;

__END__

prints:

hi
Bar says hi
Ber says hi
Bee says hi

in fact, if you look around, you wouldn't even find Bar.pm, Ber.pm or Bee.pm
anywhere because they only exist during your program runs and are deleted
automatically when your program ends. the user never know the existance of
them but are available for use when they need it! a pretty neat idea but
kind of dangerous (especially if you are downloading the modules from the
Net). you can use this technique (if you really want to do that and know
exactly what you are doing) to build arbitary complex class on the fly. the
idea is very simply though. again, without knowing what you are really
trying to accomplish, i can't recommand anything else.

david



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to