Gentoo Archives: gentoo-perl

From: antoine.raillon@××××××.net
To: gentoo-perl@l.g.o
Subject: [gentoo-perl] r11 - code
Date: Thu, 12 May 2005 21:57:20
Message-Id: 20050512215629.5ABF68280EB@gredin.dragou.net
1 Author: sniper
2 Date: 2005-05-11 06:39:30 +0200 (Wed, 11 May 2005)
3 New Revision: 11
4
5 Modified:
6 code/g-cpan.pl
7 Log:
8 Cleaning code
9
10 New construction with while() for readdir = improve memory usage and get rid of List::Util prereq
11
12
13
14 Modified: code/g-cpan.pl
15 ===================================================================
16 --- code/g-cpan.pl 2005-05-11 03:54:31 UTC (rev 10)
17 +++ code/g-cpan.pl 2005-05-11 04:39:30 UTC (rev 11)
18 @@ -10,7 +10,6 @@
19 use diagnostics;
20 use File::Spec;
21 use File::Path;
22 -use List::Util qw(first);
23
24 use constant MAKE_CONF => '/etc/make.conf';
25 use constant PATH_PKG_DEV_PERL => '/var/db/pkg/dev-perl';
26 @@ -35,7 +34,7 @@
27 use constant ERR_FOLDER_NOTFOUND => "Couldn't find folder '%s'"; # foldername
28 use constant ERR_OPEN_READ => "Couldn't open (read) file'%s' : %s"; # filename, $!
29 use constant ERR_OPEN_WRITE => "Couldn't open (write) file'%s' : %s"; # filename, $!
30 -use constant ERR_OPEN_FOLDER => "Couldn't open folder '%s', %s"; # foldername, $!
31 +use constant ERR_FOLDER_OPEN => "Couldn't open folder '%s', %s"; # foldername, $!
32 use constant ERR_FOLDER_CREATE => "Couldn't create folder '%s' : %s"; # foldername, $!
33
34
35 @@ -242,32 +241,34 @@
36 }
37
38 sub ebuild_exists {
39 - my ($dir) = @_;
40 + my ($dir) = lc $_[0];
41
42 # need to try harder here - see &portage_dir comments.
43 # should return an ebuild name from this, as case matters.
44
45 # see if an ebuild for $dir exists already. If so, return its name.
46 my $found = '';
47 -
48 + SOURCE_FOLDER:
49 foreach my $sdir (@PORTAGE_DEV_PERL, @OVERLAY_PERLS, $perldev_overlay, @TMP_DEV_PERL_DIRS) {
50 next if not -d $sdir;
51 -
52 - opendir PDIR, $sdir or fatal(ERR_OPEN_FOLDER, $sdir, $!);
53 - # FIXME Sniper
54 - # we have to use while() construction otherwise we full memory and we read ALL THE folder
55 - # even if we found the ebiuld on the 'first place', btw we can get rid of List::Util
56 - my @dirs = readdir(PDIR);
57 - closedir PDIR;
58 - $found ||= first { lc($_) eq lc($dir) }(@dirs);
59 - if ( ($found) && ($verbose) ) {
60 - print "$0: Looking for ebuilds in $sdir, found $found so far.\n";
61 + opendir PDIR, $sdir or fatal(ERR_FOLDER_OPEN, $sdir, $!);
62 + while(my $file = readdir PDIR) {
63 + if(lc $file eq $dir) {
64 + $found = $dir;
65 + print "$0: Looking for ebuilds in $sdir, found $found so far.\n" if $verbose;
66 + close PDIR;
67 + last SOURCE_FOLDER;
68 + }
69 }
70 + closedir PDIR;
71 }
72
73 # check for ebuilds that have been created by g-cpan.pl
74 for my $ebuild (@ebuild_list) {
75 - $found = $ebuild if ( $ebuild eq $dir );
76 + if($ebuild eq $dir) {
77 + $found = $ebuild;
78 + last;
79 + }
80 }
81
82 return $found;
83 @@ -279,51 +280,45 @@
84 # FIXME Sniper
85 # Do we really need regexp here ?
86 if ( $sdir =~ m/perl-gcpan/ ) {
87 - opendir PDIR, $sdir;
88 # FIXME Sniper
89 - # use while() here
90 - my @dirs = readdir(PDIR);
91 - closedir PDIR;
92 - foreach my $dir (@dirs) {
93 - push @g_list, $dir
94 - unless ( ( $dir eq "." ) or ( $dir eq ".." ) );
95 + # maybee replace fatal by "warn and next folder" ?
96 + opendir PDIR, $sdir or fatal(ERR_FOLDER_OPEN, $sdir, $!);
97 + while(my $file = readdir PDIR) {
98 + next if $file eq '.'
99 + or $file eq '..';
100 + push @g_list, $file;
101 }
102 -
103 + closedir PDIR;
104 }
105 }
106 return @g_list;
107 }
108
109 sub build_catdep {
110 -
111 # Needed a way to add category to the dependancy instead of hardcoding dev-perl :/
112 # On the upside, at this point we know the ebuild exists *somewhere* so we just need to locate it
113 - my ($dir) = @_;
114 -
115 + my ($dir) = lc $_[0];
116 my $found = '';
117
118 # FIXME Sniper
119 # not nice construct, put grep inside
120 - foreach my $sdir (
121 - grep { -d $_ } (
122 - @PORTAGE_DEV_PERL, @OVERLAY_PERLS,
123 - $perldev_overlay, @TMP_DEV_PERL_DIRS
124 - )
125 - )
126 - {
127 - opendir PDIR, $sdir;
128 + foreach my $sdir (@PORTAGE_DEV_PERL, @OVERLAY_PERLS, $perldev_overlay, @TMP_DEV_PERL_DIRS) {
129 + next if not -d $sdir;
130 # FIXME Sniper
131 - # use while() here
132 - my @dirs = readdir(PDIR);
133 - closedir PDIR;
134 - $found ||= first { lc($_) eq lc($dir) }(@dirs);
135 - if ($found) {
136 - $sdir =~ s/.*\///;
137 - $found = "$sdir/$found";
138 - return $found;
139 + # maybee replace fatal by "warn and next folder" ?
140 + opendir PDIR, $sdir or fatal(ERR_FOLDER_OPEN, $sdir, $!);
141 + while(my $file = readdir PDIR) {
142 + if(lc $file eq $dir) {
143 + $sdir =~ s/.*\///;
144 + $found = "$sdir/$found";
145 + close PDIR;
146 + return $found;
147 + }
148 }
149 + closedir PDIR;
150 }
151 -
152 + # TODO Sniper
153 + # if we are here, $found if undef, what to do ?
154 }
155
156 sub module_check {
157 @@ -364,16 +359,14 @@
158 my $fulldir = File::Spec->catdir( $perldev_overlay, $dir );
159 my $filesdir = File::Spec->catdir( $fulldir, 'files' );
160 unless ( -d $fulldir ) {
161 + print "Create folder '$fulldir'\n" if $verbose;
162 mkdir($fulldir, 0755) or fatal(ERR_FOLDER_CREATE, $fulldir, $!);
163 }
164 unless ( -d $filesdir ) {
165 + print "Create folder '$filesdir'\n" if $verbose;
166 mkdir($filesdir, 0755) or fatal(ERR_FOLDER_CREATE, $filesdir, $!);
167 }
168
169 - # FIXME Sniper
170 - # these tests are useles since done during mkdir()
171 - unless ( -d $fulldir ) { die "$fulldir not created!!\n" }
172 - unless ( -d $filesdir ) { die "$fulldir not created!!\n" }
173
174 # What to call this ebuild?
175 # CGI::Builder's '1.26+' version breaks portage
176 @@ -391,10 +384,8 @@
177 # Remove double .'s - happens on occasion with odd packages
178 $filenamever =~ s/\.$//;
179
180 - my $ebuild =
181 - File::Spec->catdir( $fulldir, "$filename-$filenamever.ebuild" );
182 - my $digest =
183 - File::Spec->catdir( $filesdir, "digest-$filename-$filenamever" );
184 + my $ebuild = File::Spec->catdir( $fulldir, "$filename-$filenamever.ebuild" );
185 + my $digest = File::Spec->catdir( $filesdir, "digest-$filename-$filenamever" );
186
187 my $desc = $module->description || 'No description available.';
188
189
190
191 --
192 gentoo-perl@g.o mailing list