use CPAN; use CPAN::Shell; BEGIN { my @Required_Modules = ("LWP::UserAgent","HTTP::Request::Common","common::sense","Silly::Werder","Bone::Easy"); my @Installed_Modules = (); my @Needed_Modules = (); my @NotInstalled_Modules= (); my @Die_If_Missing = ("LWP::UserAgent","HTTP::Request::Common","common::sense","Silly::Werder","Bone::Easy"); foreach (@Required_Modules) { #Eval require * for each module required. eval "require ($_)"; #See from output if module is not already installed - if so, then add to list of modules needing install. if ($@ =~ m/^Can\'t locate/){push(@Needed_Modules,$_)} #If modules appears to already be installed, add to list of modules installed. else {push(@Installed_Modules,$_)} } #For each entry on list of modules needing to be installed: foreach (@Needed_Modules) { #Attempt to install module using cpan #my $CPAN_Install = `cpan -I $_`; #print $CPAN_Install; CPAN::Shell->install($_); #Parse CPAN output my @CPAN_Error = split("\n",$CPAN_Install); #push module to list of installed modules unless there was a CPAN error. push(@Installed_Modules,$_) unless $CPAN_Error[$#CPAN_Error] =~ m/^>\(error\): Skipping/; #push module to list of modules note installed if there was a CPAN error. push(@NotInstalled_Modules,$_) if $CPAN_Error[$#CPAN_Error] =~ m/^>\(error\): Skipping/; } foreach(@Installed_Modules){print ("$_\n")} foreach(@NotInstalled_Modules){print ("$_\n")} ; foreach(@NotInstalled_Modules) { my $Missing_Module = $_; foreach(@Die_If_Missing) { die("Could not find / instal critical module!") if $Missing_Module eq $_; } } ; } PickupLine(); sub PickupLine { require Bone::Easy; print pickup; }