-sub MY::libscan {
- my ($self,$path) = @_;
-
- # set up the recursion
- if (-d $path) { 1; }
- elsif ($path !~ /\//) { $path = ''; }
- # from here
- # reimplementation of buildrelease and Install::installfiles
- # ban some shell specials too
- elsif ($path =~ /(\/CVS\/|\.(bak|orig|PL)$|\/,|\/t\/|[^\$]\(| )/) { $path = ''; }
- elsif (
- $path =~ s:\)/misc:\)/intranet/scripts: ||
- $path =~ s:\)/updater:\)/intranet/scripts/updater: ||
- $path =~ s:\)/z3950/(processz3950queue|.*sh):\)/intranet/scripts/z3950daemon/\1: ||
- $path =~ s:\)/z3950:\)/intranet/cgi-bin/z3950: ||
- $path =~ s:\)/koha-tmpl/intranet-tmpl:\)/intranet/htdocs/intranet-tmpl: ||
- $path =~ s:\)/koha-tmpl/intranet.html:\)/intranet/htdocs/index.html: ||
- $path =~ s:\)/koha-tmpl/opac-tmpl:\)/opac/htdocs/opac-tmpl: ||
- $path =~ s:\)/koha-tmpl/opac.html:\)/opac/htdocs/index.html: ||
- $path =~ s:\)/opac:\)/opac/cgi-bin:
- ) { 1; }
- elsif ($path !~ /\.p[lm]$/) { $path = ''; }
- elsif ($path !~ /\)\/C4/) { $path =~ s!/!/intranet/cgi-bin/!; }
-
- #print STDERR $path."\n";
-
- return($path);
-
- }
+=head1 FUNCTIONS
+
+=head2 hashdir
+
+This function recurses through the directory structure and builds
+a hash of hashes containing the structure with arrays holding filenames.
+This directory hashing routine was taken from BrowserUK @ http://www.perlmonks.org/?node_id=219919
+
+=cut
+
+sub hashdir{
+ my $dir = shift;
+ opendir my $dh, $dir or die $!;
+ my $tree = {}->{$dir} = {};
+ while( my $file = readdir($dh) ) {
+ next if $file =~ m/^\.{1,2}/;
+ my $path = $dir .'/' . $file;
+ $tree->{$file} = hashdir($path), next if -d $path;
+ push @{$tree->{'.'}}, $file;
+ }
+ return $tree;
+}
+
+=head2 unhashdir
+
+This function unhashes the hash of hashes generated by hashdir().
+This directory unhashing routine is the personal work of Chris Nighswonger (fbcit).
+Modified here to build koha makefile. It lists all files and where to install each one.
+It then returns a hash reference suitable for the PM variable above.
+
+=cut
+
+sub unhashdir{
+ my $dirhash = shift;
+ my $dirlevel = shift;
+ my $toplevel = $dirlevel;
+ for my $k1 ( sort keys %$dirhash ) {
+ if ($k1 ne '.' && $k1 ne '') {
+ $dirlevel = ( $dirlevel ? $dirlevel . '/' . $k1 : $k1 );
+ &unhashdir($dirhash->{ $k1 }, $dirlevel);
+ $dirlevel = $toplevel;
+ }
+ elsif ( $k1 eq '.' ) {
+ foreach $file ( @{$dirhash->{ $k1 }} ) {
+# TODO: There are some hacks here that may be able to be improved... -fbcit
+ if ( $file =~ /^./ ) { next; } # skip hidden files and directories.
+
+ elsif ( $file =~ /\.pm/ && $dirlevel =~ /C4/ ) { $result{ ($dirlevel ? $dirlevel . '/' . $file : $file) } = '$(INST_LIBDIR)/' . ($dirlevel ? $dirlevel . '/' . $file : $file); } # C4/*.pm is copied to perl's lib namespace.
+
+ elsif ( $dirlevel !~ /koha-tmpl/ && $dirlevel =~ /(installer|errors)/ ) { $result{ ($dirlevel ? $dirlevel . '/' . $file : $file) } = '$(PREFIX)/lib/cgi-bin/koha/' . ($dirlevel ? $dirlevel . '/' . $file : $file); } # error templates are copied to $(PREFIX)/lib/cgi-bin/koha/
+
+ elsif ( $dirlevel =~ /koha-tmpl/ && $dirlevel !~ /errors/ ) { $result{ ($dirlevel ? $dirlevel . '/' . $file : $file) } = '$(INST_LIBDIR)/koha/templates/' . ($dirlevel ? $dirlevel . '/' . $file : $file); } # error templates are copied to $(INST_LIBDIR)/koha/templates/
+
+ elsif ( $dirlevel =~ /(misc|rss)/ ) { $result{ ($dirlevel ? $dirlevel . '/' . $file : $file) } = '$(INST_LIBDIR)/koha/' . ($dirlevel ? $dirlevel . '/' . $file : $file); } # misc & rss are copied to koha,
+
+# elsif ( $dirlevel =~ /(intranet-tmpl|opac-tmpl)/ ) { $result{ ($dirlevel ? $dirlevel . '/' . $file : $file) } = '$(INST_LIBDIR)/koha/templates/' . ($dirlevel ? $dirlevel . '/' . $file : $file); } # Templates are copied to koha/templates,
+
+ elsif ( $file !~ /\.pl/ && $dirlevel =~ /etc/ ) { $result{ ($dirlevel ? $dirlevel . '/' . $file : $file) } = '$(PREFIX)/share/koha/' . ($dirlevel ? $dirlevel . '/' . $file : $file); } # Misc etc to koha/etc
+
+ elsif ( $file =~ /\.pl/ ) { $result{ ($dirlevel ? $dirlevel . '/' . $file : $file) } = '$(PREFIX)/lib/cgi-bin/koha/' . ($dirlevel ? $dirlevel . '/' . $file : $file); } # CGIs are copied to $(PREFIX)/lib/cgi-bin/koha/ print $result{ ($dirlevel ? $dirlevel . '/' . $file : $file)},"\n\n";
+
+ }
+ next;
+ }
+ }
+ return \%result;
+}
+
+__END__
+
+
+=head1 SEE ALSO
+
+ExtUtils::MakeMaker(3)
+
+=head1 AUTHORS
+
+MJ Ray mjr at phonecoop.coop
+
+=cut
+