[Petal] Adding support for PAR
William McKee
william at knowmad.com
Sat Mar 12 12:57:04 GMT 2005
On Wed, Mar 09, 2005 at 12:42:40PM +0000, Bruno Postle wrote:
> The patch applies cleanly and passes the tests (without PAR
> installed), though it doesn't contain any changes to
> MKDoc::XML::Decode?
I was just wanting to get feedback on the code--thanks for the reply.
I've attached the patch to MKDoc to this message which includes your
suggestion.
> Shouldn't it be something like this?:
>
> if (ref $include_dir eq 'CODE' and keys %PAR::LibCache)
Yes, that makes more sense. I added the 'next unless' line after
realizing that there is the possibility that the coderef is not a PAR
object. This line really doesn't ensure that it isn't but is the closest
solution I could find.
Basically, it assumes that if PAR is loaded and there are entries in the
%LibCache hash then loop through the entries in the %LibCache and add
them to the @modules list. This will work in most cases. It will
probably add duplicate entries to the @modules list when the programmer
uses coderefs in the @INC in addition to PAR (see `perldoc -f require`
for the details).
I'll admit my ignorance and say that I didn't even know it was possible
to use coderefs until I began using PAR. Is anyone on this list using
coderefs in @INC? Will it matter if @modules contains duplicates when
MKDoc/Petal build up the modules list? It doesn't look like it but I
have not tested this theory.
> You also a moved a '{', this looks like a bugfix?:
Actually I thought it was a '}' that I moved. I did that because the
original code had the foreach loop inside of a different block. I needed
to move it out a level so that PAR modules could be included in the
MODIFIERS hashref. I didn't think it was a bugfix but didn't look too
deeply into the matter before moving it.
Thanks,
William
PS - Is there a publicly accessible CVS repository for MKDoc? Is it the
same as the one for Petal?
--
Knowmad Services Inc.
http://www.knowmad.com
-------------- next part --------------
--- lib/MKDoc/XML/Decode.pm.orig 2005-03-09 09:35:42.000000000 -0500
+++ lib/MKDoc/XML/Decode.pm 2005-03-09 09:49:15.000000000 -0500
@@ -21,6 +21,24 @@
# import all plugins once
foreach my $include_dir (@INC)
{
+ my @modules;
+ # Support for PAR archives
+ if (ref $include_dir eq 'CODE' && keys %PAR::LibCache)
+ {
+ while (my ($filename, $zip) = each %PAR::LibCache)
+ {
+ my @mods = $zip->membersMatching( "MKDoc/XML/Decode/" );
+ foreach my $mod (@mods)
+ {
+ my $fn = $mod->fileName;
+ my ($pm) = $fn =~ /\/(\w+)\.pm$/;
+ #warn "$fn = $pm";
+ push @modules, $pm;
+ }
+ }
+ }
+ else
+ {
my $dir = "$include_dir/MKDoc/XML/Decode";
if (-e $dir and -d $dir)
{
@@ -29,30 +47,32 @@
next;
};
- my @modules = map { s/\.pm$//; $_ }
+ @modules = map { s/\.pm$//; $_ }
grep /\.pm$/,
grep !/^\./,
readdir (DD);
closedir DD;
-
- foreach my $module (@modules)
- {
- $module =~ /^(\w+)$/;
- $module = $1;
- eval "use MKDoc::XML::Decode::$module";
- $@ and warn "Cannot import module $module. Reason: $@";
-
- my $name = "MKDoc::XML::Decode::$module"->can ('module_name') ?
- "MKDoc::XML::Decode::$module"->module_name() :
- lc ($module);
-
- $Modules{$name} = "MKDoc::XML::Decode::$module";
- }
+ }
}
+
+ foreach my $module (@modules)
+ {
+ $module =~ /^(\w+)$/;
+ $module = $1;
+ eval "use MKDoc::XML::Decode::$module";
+ $@ and warn "Cannot import module $module. Reason: $@";
+
+ my $name = "MKDoc::XML::Decode::$module"->can ('module_name') ?
+ "MKDoc::XML::Decode::$module"->module_name() :
+ lc ($module);
+
+ $Modules{$name} = "MKDoc::XML::Decode::$module";
+ }
}
+
sub new
{
my $class = shift;
More information about the Petal
mailing list