Skip Menu |

This queue is for tickets about the Module-Build CPAN distribution.

Report information
The Basics
Id: 4964
Status: resolved
Priority: 0/
Queue: Module-Build

People
Owner: Nobody in particular
Requestors: NUFFIN [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Wishlist
Broken in: (no value)
Fixed in: (no value)



Subject: distdir postprocessing (pod wrapping, tab expansion)
The following patch will allow Module::Build to automatically wrap pod sections and expand tabs using some modules. The documentation has also been patched. The modifications were made as high up the file as logically possible, to ease repositioning. Motivation: people like me, who use real tabs and don't wrap their code, should do so, because we are not the majority. Reasons not to integrate: The distribution tarball will differ from the working copy, making patch submission be icky. But this is not on by default, so... Distribution post (or pre, from the perspective of the end user) processing in general can be deemed a bad thing from this perspective. Implementation is sort of qnd Possible extension: use Perl::Tidy
diff -ur Module-Build-0.22/lib/Module/Build/Base.pm Module-Build-0.22-Text-Tabs_and_Pod-Wrap/lib/Module/Build/Base.pm --- Module-Build-0.22/lib/Module/Build/Base.pm Sun Jan 11 06:19:59 2004 +++ Module-Build-0.22-Text-Tabs_and_Pod-Wrap/lib/Module/Build/Base.pm Sat Jan 17 15:43:07 2004 @@ -12,6 +12,70 @@ use Data::Dumper (); use IO::File (); +##### place wherever ##### + +sub expand_tabs { return (@_ ? $_ = shift : $_ ) for shift->{properties}{expand_tabs} } +sub wrap_pod { return (@_ ? $_ = shift : $_) for shift->{properties}{wrap_pod} } + +sub _pp_wrap_pod { + my $self = shift; + + require Pod::Wrap or warn "Can't wrap pod because Pod::Wrap is not available" and return; + require Pod::Find; + + my %args = @_; + my $file = File::Spec->catfile($args{in}, $args{file}); + + $Text::Wrap::columns = $self->wrap_pod + 0 if eval { $self->wrap_pod + 0 || 1 } && not $@; + + if (Pod::Find::contains_pod($file)) { + require File::Temp; + + my ($out, $tmpfile) = File::Temp::tempfile(DIR => $args{in}, UNLINK => 0) or die "Couldn't create tempfile: $!"; # in the destination dir, because sometimes /tmp or equivelent and what we'll work on aren't on the same filesystem + + my $w = new Pod::Wrap; + + open PP_INFILE, "<", $file or die "Couldn't open $file for reading: $!"; + + $w->parse_from_filehandle(\*PP_INFILE, $out); + + close PP_INFILE; + close $out; + + unlink $file or die "Couldn't remove $file: $!"; + rename $tmpfile, $file or die "Couldn't rename $tmpfile to $file: $!"; + } +} + +sub _pp_expand_tabs { + my $self = shift; + + + + require Text::Tabs; + require File::Temp; + + my %args = @_; + my $file = File::Spec->catfile($args{in}, $args{file}); + + $Text::Tabs::tabstop = $self->expand_tabs + 0 if eval { $self->expand_tabs + 0 || 1 } && not $@; + + my ($out, $tmpfile) = File::Temp::tempfile(DIR => $args{in}, UNLINK => 0) or die "Couldn't create tempfile: $!"; + + open PP_INFILE, "<", $file or die "Couldn't open $file for reading: $!"; + + while(<PP_INFILE>){ + print {$out} Text::Tabs::expand($_); + } + + close PP_INFILE; + close $out; + + unlink $file or die "Couldn't remove $file: $!"; + rename $tmpfile, $file or die "Couldn't rename $tmpfile to $file: $!"; +} + + #################### Constructors ########################### sub new { my $self = shift()->_construct(@_); @@ -1570,6 +1634,14 @@ foreach my $file (keys %$dist_files) { $self->copy_if_modified(from => $file, to_dir => $dist_dir, verbose => 0); } + + if (my @pp = map { "_pp_$_" } grep { $self->$_() } qw/expand_tabs wrap_pod/) { + foreach my $file (keys %$dist_files){ + foreach my $pp (@pp){ + $self->$pp(file => $file, in => $dist_dir); + } + } + } $self->_sign_dir($dist_dir) if $self->{properties}{sign}; } diff -ur Module-Build-0.22/lib/Module/Build.pm Module-Build-0.22-Text-Tabs_and_Pod-Wrap/lib/Module/Build.pm --- Module-Build-0.22/lib/Module/Build.pm Sun Jan 11 06:19:59 2004 +++ Module-Build-0.22-Text-Tabs_and_Pod-Wrap/lib/Module/Build.pm Sat Jan 17 15:49:57 2004 @@ -214,6 +214,17 @@ =over 4 +=item expand_tabs + +If true, distribution files' tabs will be expanded using L<Text::Tabs>. +If it is a number, $Text::Tabs::tabstop will be set to it's value. + +=item wrap_pod + +If true, distribution files' pod sections will be wrapped using +L<Pod::Wrap>. If it is a number, $Text::Wrap::columns will be set to +it's value. + =item module_name The C<module_name> is a shortcut for setting default values of
[guest - Sat Jan 17 08:57:11 2004]: Show quoted text
> Reasons not to integrate: > > The distribution tarball will differ from the working copy, making > patch submission be icky. But this is not on by default, so... > Distribution post (or pre, from the perspective of the end user) > processing in general can be deemed a bad thing from this > perspective.
Yeah, I don't think I want to apply this for that reason. It's even conceivable that the module could break without the author's knowledge while building the distribution. I recommend getting word-wrapping and tab-expansion working in your editor, which is where this kind of stuff belongs IMO. Once we get the plugin architecture for M::B figured out, you could make a plugin for this, though. -Ken