updated git and svn scripts
[xrzperl.git] / pmlist
blob9aee7502cdcefb75c1ad4eec717b9eca11f9afc8
1 #!/usr/bin/perl -w
2 ###APPNAME: pmlist
3 ###APPAUTHOR: xiaoranzzz
4 ###APPDATE: Sun Apr 6 15:07:18 2008
5 ###APPVER: 0.1
6 ###APPDESC: List local perl modules
7 ###APPUSAGE: [pattern]
8 ###APPEXAMPLE: pmlist MyPlace::NewModule
9 ###APPOPTION:
10 use strict;
12 #ENV variable MUST be defined somewhere,
13 #FOR perl to search modules from,
14 #OR nothing will work
15 use lib $ENV{XR_PERL_MODULE_DIR};
16 use MyPlace::Script::Usage qw/help_required/;
17 exit 0 if(help_required($0,@ARGV));
19 my $exp=shift;
20 $exp=qr/$exp/ if($exp);
22 sub listmodule($$$);
24 sub listmodule($$$) {
25 my $dir=shift;
26 my $exp=shift;
27 my $prefix=shift;
28 my @result=();
29 $prefix="" unless($prefix);
30 my @dirs;
31 my @files;
32 chdir $dir or return \@result;
33 foreach(glob("*")) {
34 next if($_ eq ".");
35 next if($_ eq "..");
36 if(-d $_) {
37 push @dirs,$_;
39 elsif(/\.pm$/) {
40 $_ =~ s/\.pm$//;
41 push @files,$_;
44 foreach(@files) {
45 my $mod=$prefix . $_;
46 push @result,$mod if((!defined($exp)) or $mod =~ m/$exp/);
48 foreach(@dirs) {
49 push @result,@{listmodule($_,$exp,$prefix . $_ . "::")};
51 return \@result;
54 foreach($ENV{XR_PERL_MODULE_DIR},@INC) {
55 my @result=@{listmodule($_,$exp,"")};
56 print join("\n",@result),"\n" if(@result);