&new: Permit 'My::Hash' itself instanation if no other class is specified.
[MyWeb.git] / ModPerlPm.pm
1 # $Id$
2 # Handle the set of ".pm" files for mod_perl
3 # Copyright (C) 2005 Jan Kratochvil <project-www.jankratochvil.net@jankratochvil.net>
4
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; exactly version 2 of June 1991 is required
8
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 # GNU General Public License for more details.
13
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17
18
19 package My::ModPerlPm;
20 require 5.6.0;  # at least 'use warnings;' but we need some 5.6.0+ modules anyway
21 our $VERSION=do { my @r=(q$Revision$=~/\d+/g); sprintf "%d.".("%03d"x$#r),@r; };
22 our $CVS_ID=q$Id$;
23 use strict;
24 use warnings;
25
26 use Carp qw(cluck confess);
27
28 use Exporter;
29 our @EXPORT=qw();
30 our @ISA=qw(Exporter);
31
32
33 # $args{"sub"}=sub { $_[0]->{"module"...}; };
34 sub list($%)
35 {
36 my($self,%args)=@_;
37
38         my $filename="make -s MODPERL_PM-print|";
39         local *F;
40         open F,$filename or confess "$filename: $!";
41         local $_;
42         my @r;
43         while (<F>) {
44                 next if !s/^MODPERL_PM:([^:]+)://;
45                 my $subdir=$1;
46                 for (split) {
47                         my %r;
48                         $r{"url"}=$subdir."/".$_;
49                         $r{"url"}=~s{^[.](/.*[.]pm)$}{$1} or confess "Invalid project: subdir=$subdir base=$_";
50                         $r{"module"}=$r{"url"};
51                         $r{"module"}=~s{^/}{} or confess "Relative module: ".$r{"module"};
52                         $r{"file"}=$r{"module"};
53                         $r{"module"}=~s{/}{::}g;
54                         $r{"module"}=~s{[.]pm$}{} or confess;
55                         -r $r{"file"} or do { warn "FIXME: Non-existing file \"".$r{"file"}."\" for URL: ".$r{"url"}; next; };
56                         do { &{$_}(\%r) if $_; } for $args{"sub"};
57                         push @r,\%r;
58                         }
59                 }
60         close F or confess "$filename: $!";
61         cluck "No modules?" if !@r;
62         return @r;
63 }
64 1;