| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | package win; | 
| 2 |  |  |  |  |  |  | our $VERSION = '0.03'; | 
| 3 |  |  |  |  |  |  | require Exporter; | 
| 4 |  |  |  |  |  |  | our @ISA = qw(Exporter); | 
| 5 |  |  |  |  |  |  |  | 
| 6 |  |  |  |  |  |  | sub import { | 
| 7 |  |  |  |  |  |  |  | 
| 8 | 1 |  |  | 1 |  | 9 | my $class = shift; | 
| 9 |  |  |  |  |  |  |  | 
| 10 | 1 |  |  |  |  | 3 | ($pkg) = (caller)[0]; | 
| 11 | 1 |  |  |  |  | 2 | $current = __PACKAGE__; | 
| 12 |  |  |  |  |  |  |  | 
| 13 | 1 |  |  |  |  | 2 | $mods = ""; | 
| 14 |  |  |  |  |  |  |  | 
| 15 | 1 | 50 |  |  |  | 6 | &rerun unless (@_); | 
| 16 |  |  |  |  |  |  |  | 
| 17 | 1 |  |  |  |  | 4 | my @list = split /,/, $_[0]; | 
| 18 | 1 |  |  |  |  | 1 | my $found = 0; | 
| 19 |  |  |  |  |  |  |  | 
| 20 |  |  |  |  |  |  |  | 
| 21 | 1 |  |  |  |  | 3 | foreach (@list) { | 
| 22 |  |  |  |  |  |  | # give me everything with or without colons. | 
| 23 | 0 |  |  |  |  | 0 | /([\w\:]+)(.*)/; | 
| 24 | 0 |  |  |  |  | 0 | $pm = "Win32/$1.pm"; | 
| 25 |  |  |  |  |  |  |  | 
| 26 |  |  |  |  |  |  | # susbstitute the colons with backslashes | 
| 27 | 0 |  |  |  |  | 0 | $pm =~ s/\:\:/\//g; | 
| 28 |  |  |  |  |  |  |  | 
| 29 |  |  |  |  |  |  | # give me the last part, which will be the file name, of the first regex. | 
| 30 | 0 |  |  |  |  | 0 | $suffix = $2; | 
| 31 | 0 |  |  |  |  | 0 | $suffix =~ s/\s+$//; | 
| 32 |  |  |  |  |  |  |  | 
| 33 |  |  |  |  |  |  | # Let's see what we find. | 
| 34 | 0 |  |  |  |  | 0 | foreach (@INC) { | 
| 35 | 0 | 0 |  |  |  | 0 | next unless ( -e "$_/$pm" ); | 
| 36 | 0 | 0 |  |  |  | 0 | open(READ, "$_/$pm") or die "Can't read $_/$pm"; | 
| 37 | 0 |  |  |  |  | 0 | while ($line = ) { | 
| 38 | 0 | 0 |  |  |  | 0 | if ( $line =~ /package\s+(Win32.*?);/i) { | 
| 39 | 0 |  |  |  |  | 0 | $mods .= "use $1$suffix;\n"; | 
| 40 | 0 |  |  |  |  | 0 | $found++; | 
| 41 | 0 |  |  |  |  | 0 | last; | 
| 42 |  |  |  |  |  |  | } | 
| 43 | 0 |  |  |  |  | 0 | next; | 
| 44 |  |  |  |  |  |  | } | 
| 45 | 0 |  |  |  |  | 0 | last; | 
| 46 |  |  |  |  |  |  | } | 
| 47 | 0 |  |  |  |  | 0 | next; | 
| 48 |  |  |  |  |  |  | } | 
| 49 |  |  |  |  |  |  |  | 
| 50 |  |  |  |  |  |  | # Now we've got to give rerun a mods variable, so what do we do if we found nothing? | 
| 51 |  |  |  |  |  |  | # Remember to let rerun catch any missing modules, not Win32-Die. | 
| 52 | 1 |  |  |  |  | 2 | my $diev = 0; | 
| 53 | 1 | 50 | 33 |  |  | 12 | if  ( ( ($found == 0) && ($#list == 0) ) || | 
|  |  |  | 33 |  |  |  |  | 
| 54 |  |  |  |  |  |  | ($found != ($#list + 1)) ) { | 
| 55 |  |  |  |  |  |  |  | 
| 56 | 0 |  |  |  |  | 0 | $mods = ""; | 
| 57 | 0 |  |  |  |  | 0 | foreach (@list) { | 
| 58 | 0 |  |  |  |  | 0 | $_ =~ s/^\s+//; | 
| 59 | 0 |  |  |  |  | 0 | $_ =~ s/\s+$//; | 
| 60 | 0 | 0 |  |  |  | 0 | if ($mods .= "use Win32::$_;\n") { | 
| 61 | 0 |  |  |  |  | 0 | $diev = 1; | 
| 62 |  |  |  |  |  |  | } | 
| 63 |  |  |  |  |  |  | } | 
| 64 |  |  |  |  |  |  | } | 
| 65 |  |  |  |  |  |  | # Must prevent Win32-Die from interferring with our error catch. | 
| 66 | 1 | 50 |  |  |  | 6 | unless ($diev) { | 
| 67 | 1 |  |  |  |  | 2 | $mods .= "use Win32::Die;\n"; | 
| 68 |  |  |  |  |  |  | } | 
| 69 |  |  |  |  |  |  |  | 
| 70 | 1 |  |  |  |  | 2 | &rerun; | 
| 71 |  |  |  |  |  |  |  | 
| 72 |  |  |  |  |  |  | } | 
| 73 |  |  |  |  |  |  |  | 
| 74 |  |  |  |  |  |  | sub rerun { | 
| 75 |  |  |  |  |  |  |  | 
| 76 | 1 |  |  | 1 | 0 | 759 | eval qq[ | 
|  | 1 |  |  | 1 |  | 172 |  | 
|  | 1 |  |  | 1 |  | 18 |  | 
|  | 1 |  |  | 2 |  | 5 |  | 
|  | 1 |  |  |  |  | 2 |  | 
|  | 1 |  |  |  |  | 19 |  | 
|  | 1 |  |  |  |  | 744 |  | 
|  | 1 |  |  |  |  | 5058 |  | 
|  | 1 |  |  |  |  | 22 |  | 
|  | 2 |  |  |  |  | 109 |  | 
| 77 |  |  |  |  |  |  | package $pkg; | 
| 78 |  |  |  |  |  |  | use Win32::Autoglob; | 
| 79 |  |  |  |  |  |  | $mods; | 
| 80 |  |  |  |  |  |  | package $current; | 
| 81 |  |  |  |  |  |  | ]; | 
| 82 | 2 | 50 |  |  |  | 1518 | if ($@) { | 
| 83 |  |  |  |  |  |  |  | 
| 84 | 0 | 0 |  |  |  |  | if ($@ =~ /Can't locate/) { | 
| 85 | 0 |  |  |  |  |  | &ppmcall; | 
| 86 |  |  |  |  |  |  | } else { | 
| 87 | 0 |  |  |  |  |  | require Carp; | 
| 88 | 0 |  |  |  |  |  | Carp::croak("$@"); | 
| 89 |  |  |  |  |  |  | } | 
| 90 |  |  |  |  |  |  | } | 
| 91 |  |  |  |  |  |  | } | 
| 92 |  |  |  |  |  |  |  | 
| 93 |  |  |  |  |  |  | sub ppmcall { | 
| 94 |  |  |  |  |  |  |  | 
| 95 | 0 |  | 0 | 0 | 0 |  | do { | 
| 96 | 0 |  |  |  |  |  | print "$@\n"; | 
| 97 | 0 |  |  |  |  |  | print "Looks like you don't have the module you requested\n"; | 
| 98 | 0 |  |  |  |  |  | print "Shall I have PPM fetch it for you? (y/n) "; | 
| 99 |  |  |  |  |  |  | } while ( ( $_ =  ) && ( $_ !~ /y|n/i ) ); | 
| 100 |  |  |  |  |  |  |  | 
| 101 | 0 | 0 |  |  |  |  | unless ( $_ =~ /y/i ) { | 
| 102 |  |  |  |  |  |  |  | 
| 103 | 0 | 0 |  |  |  |  | print "Bye!\n" and exit; | 
| 104 |  |  |  |  |  |  |  | 
| 105 |  |  |  |  |  |  | } | 
| 106 |  |  |  |  |  |  |  | 
| 107 | 1 |  |  | 1 |  | 6981 | use File::Which qw(which); | 
|  | 1 |  |  |  |  | 1003 |  | 
|  | 1 |  |  |  |  | 243 |  | 
| 108 | 0 | 0 |  |  |  |  | unless ( defined( which('ppm') ) ) { | 
| 109 | 0 |  |  |  |  |  | print <<'EOF'; | 
| 110 |  |  |  |  |  |  |  | 
| 111 |  |  |  |  |  |  | Bad news: I can't find PPM in your path. | 
| 112 |  |  |  |  |  |  |  | 
| 113 |  |  |  |  |  |  | Most likely PPM is on your system. | 
| 114 |  |  |  |  |  |  | Search for PPM and put its location in your path. Or you can download PPM | 
| 115 |  |  |  |  |  |  | from http://www.activestate.com. Look under their Perl section. | 
| 116 |  |  |  |  |  |  | Exiting ... | 
| 117 |  |  |  |  |  |  |  | 
| 118 |  |  |  |  |  |  | EOF | 
| 119 |  |  |  |  |  |  |  | 
| 120 | 0 |  |  |  |  |  | exit; | 
| 121 |  |  |  |  |  |  | } | 
| 122 |  |  |  |  |  |  |  | 
| 123 | 0 |  |  |  |  |  | my (@ppmods) = $mods =~ /(Win32::[\w\:]+).*?;/g; | 
| 124 | 0 |  |  |  |  |  | foreach my $pm (@ppmods) { | 
| 125 |  |  |  |  |  |  | #my $pm = $_; | 
| 126 |  |  |  |  |  |  |  | 
| 127 | 0 |  |  |  |  |  | $pm =~ s/::/\//g; | 
| 128 | 0 |  |  |  |  |  | $pm = "$pm" . ".pm"; | 
| 129 |  |  |  |  |  |  |  | 
| 130 | 0 |  |  |  |  |  | my $found = 0; | 
| 131 | 0 |  |  |  |  |  | foreach (@INC) { | 
| 132 | 0 | 0 |  |  |  |  | ++$found if ( -e "$_/$pm" ); | 
| 133 |  |  |  |  |  |  | } | 
| 134 | 0 | 0 |  |  |  |  | unless ($found) { | 
| 135 | 0 |  |  |  |  |  | print "Please wait ...\n"; | 
| 136 | 0 |  |  |  |  |  | print "Activating PPM ( ctrl-c to abort )\n"; | 
| 137 | 0 |  |  |  |  |  | my $ppm_results = `ppm install $_`; | 
| 138 | 0 |  |  |  |  |  | print "$ppm_results\n"; | 
| 139 |  |  |  |  |  |  | } | 
| 140 |  |  |  |  |  |  | } | 
| 141 |  |  |  |  |  |  |  | 
| 142 | 0 | 0 |  |  |  |  | print "PPM done. Goodbye.\n" and exit; | 
| 143 |  |  |  |  |  |  |  | 
| 144 |  |  |  |  |  |  | } | 
| 145 |  |  |  |  |  |  | 1; | 
| 146 |  |  |  |  |  |  | __END__ |