[Bps-public-commit] r18772 - in RT-Extension-ExtractCustomFieldValues: inc/Module inc/Module/Install lib/RT/Action lib/RT/Extension

alexmv at bestpractical.com alexmv at bestpractical.com
Thu Mar 12 20:25:45 EDT 2009


Author: alexmv
Date: Thu Mar 12 20:25:44 2009
New Revision: 18772

Modified:
   RT-Extension-ExtractCustomFieldValues/Changes
   RT-Extension-ExtractCustomFieldValues/META.yml
   RT-Extension-ExtractCustomFieldValues/inc/Module/Install.pm
   RT-Extension-ExtractCustomFieldValues/inc/Module/Install/Base.pm
   RT-Extension-ExtractCustomFieldValues/inc/Module/Install/Can.pm
   RT-Extension-ExtractCustomFieldValues/inc/Module/Install/Fetch.pm
   RT-Extension-ExtractCustomFieldValues/inc/Module/Install/Makefile.pm
   RT-Extension-ExtractCustomFieldValues/inc/Module/Install/Metadata.pm
   RT-Extension-ExtractCustomFieldValues/inc/Module/Install/Win32.pm
   RT-Extension-ExtractCustomFieldValues/inc/Module/Install/WriteAll.pm
   RT-Extension-ExtractCustomFieldValues/lib/RT/Action/ExtractCustomFieldValues.pm
   RT-Extension-ExtractCustomFieldValues/lib/RT/Extension/ExtractCustomFieldValues.pm

Log:
Dev release of 2.99, which is a fair rewrite, and supports extraction from multipart messages

Modified: RT-Extension-ExtractCustomFieldValues/Changes
==============================================================================
--- RT-Extension-ExtractCustomFieldValues/Changes	(original)
+++ RT-Extension-ExtractCustomFieldValues/Changes	Thu Mar 12 20:25:44 2009
@@ -1,3 +1,7 @@
+2.99
+Rewrite to use method calls, not functions, and support extraction
+from _all_ text/plain MIME parts, not just the first.
+
 2.05
 Previous versions could find disabled versions of custon fields if
 they had duplicate names.  Work around this by not using

Modified: RT-Extension-ExtractCustomFieldValues/META.yml
==============================================================================
--- RT-Extension-ExtractCustomFieldValues/META.yml	(original)
+++ RT-Extension-ExtractCustomFieldValues/META.yml	Thu Mar 12 20:25:44 2009
@@ -15,4 +15,4 @@
     - po
     - var
     - inc
-version: 2.05
+version: 2.99_01

Modified: RT-Extension-ExtractCustomFieldValues/inc/Module/Install.pm
==============================================================================
--- RT-Extension-ExtractCustomFieldValues/inc/Module/Install.pm	(original)
+++ RT-Extension-ExtractCustomFieldValues/inc/Module/Install.pm	Thu Mar 12 20:25:44 2009
@@ -30,7 +30,11 @@
 	# This is not enforced yet, but will be some time in the next few
 	# releases once we can make sure it won't clash with custom
 	# Module::Install extensions.
-	$VERSION = '0.70';
+	$VERSION = '0.79';
+
+	*inc::Module::Install::VERSION = *VERSION;
+	@inc::Module::Install::ISA     = __PACKAGE__;
+
 }
 
 
@@ -81,7 +85,7 @@
 
 # Build.PL was formerly supported, but no longer is due to excessive
 # difficulty in implementing every single feature twice.
-if ( $0 =~ /Build.PL$/i or -f 'Build.PL' ) { die <<"END_DIE" }
+if ( $0 =~ /Build.PL$/i ) { die <<"END_DIE" }
 
 Module::Install no longer supports Build.PL.
 
@@ -95,14 +99,20 @@
 
 
 
+# To save some more typing in Module::Install installers, every...
+# use inc::Module::Install
+# ...also acts as an implicit use strict.
+$^H |= strict::bits(qw(refs subs vars));
+
+
+
+
+
 use Cwd        ();
 use File::Find ();
 use File::Path ();
 use FindBin;
 
-*inc::Module::Install::VERSION = *VERSION;
- at inc::Module::Install::ISA     = __PACKAGE__;
-
 sub autoload {
 	my $self = shift;
 	my $who  = $self->_caller;
@@ -115,8 +125,10 @@
 			goto &$code unless $cwd eq $pwd;
 		}
 		$$sym =~ /([^:]+)$/ or die "Cannot autoload $who - $sym";
-		unshift @_, ( $self, $1 );
-		goto &{$self->can('call')} unless uc($1) eq $1;
+		unless ( uc($1) eq $1 ) {
+			unshift @_, ( $self, $1 );
+			goto &{$self->can('call')};
+		}
 	};
 }
 
@@ -145,8 +157,7 @@
 }
 
 sub preload {
-	my ($self) = @_;
-
+	my $self = shift;
 	unless ( $self->{extensions} ) {
 		$self->load_extensions(
 			"$self->{prefix}/$self->{path}", $self
@@ -202,6 +213,7 @@
 		$args{path}  =~ s!::!/!g;
 	}
 	$args{file}     ||= "$args{base}/$args{prefix}/$args{path}.pm";
+	$args{wrote}      = 0;
 
 	bless( \%args, $class );
 }
@@ -238,7 +250,7 @@
 sub load_extensions {
 	my ($self, $path, $top) = @_;
 
-	unless ( grep { lc $_ eq lc $self->{prefix} } @INC ) {
+	unless ( grep { !ref $_ and lc $_ eq lc $self->{prefix} } @INC ) {
 		unshift @INC, $self->{prefix};
 	}
 
@@ -277,9 +289,9 @@
 		# correctly.  Otherwise, root through the file to locate the case-preserved
 		# version of the package name.
 		if ( $subpath eq lc($subpath) || $subpath eq uc($subpath) ) {
-			open PKGFILE, "<$subpath.pm" or die "find_extensions: Can't open $subpath.pm: $!";
-			my $in_pod = 0;
-			while ( <PKGFILE> ) {
+			my $content = Module::Install::_read($subpath . '.pm');
+			my $in_pod  = 0;
+			foreach ( split //, $content ) {
 				$in_pod = 1 if /^=\w/;
 				$in_pod = 0 if /^=cut/;
 				next if ($in_pod || /^=cut/);  # skip pod text
@@ -289,7 +301,6 @@
 					last;
 				}
 			}
-			close PKGFILE;
 		}
 
 		push @found, [ $file, $pkg ];
@@ -298,6 +309,13 @@
 	@found;
 }
 
+
+
+
+
+#####################################################################
+# Utility Functions
+
 sub _caller {
 	my $depth = 0;
 	my $call  = caller($depth);
@@ -308,6 +326,44 @@
 	return $call;
 }
 
+sub _read {
+	local *FH;
+	open FH, "< $_[0]" or die "open($_[0]): $!";
+	my $str = do { local $/; <FH> };
+	close FH or die "close($_[0]): $!";
+	return $str;
+}
+
+sub _write {
+	local *FH;
+	open FH, "> $_[0]" or die "open($_[0]): $!";
+	foreach ( 1 .. $#_ ) { print FH $_[$_] or die "print($_[0]): $!" }
+	close FH or die "close($_[0]): $!";
+}
+
+# _version is for processing module versions (eg, 1.03_05) not
+# Perl versions (eg, 5.8.1).
+
+sub _version ($) {
+	my $s = shift || 0;
+	   $s =~ s/^(\d+)\.?//;
+	my $l = $1 || 0;
+	my @v = map { $_ . '0' x (3 - length $_) } $s =~ /(\d{1,3})\D?/g;
+	   $l = $l . '.' . join '', @v if @v;
+	return $l + 0;
+}
+
+# Cloned from Params::Util::_CLASS
+sub _CLASS ($) {
+	(
+		defined $_[0]
+		and
+		! ref $_[0]
+		and
+		$_[0] =~ m/^[^\W\d]\w*(?:::\w+)*$/s
+	) ? $_[0] : undef;
+}
+
 1;
 
-# Copyright 2008 Adam Kennedy.
+# Copyright 2008 - 2009 Adam Kennedy.

Modified: RT-Extension-ExtractCustomFieldValues/inc/Module/Install/Base.pm
==============================================================================
--- RT-Extension-ExtractCustomFieldValues/inc/Module/Install/Base.pm	(original)
+++ RT-Extension-ExtractCustomFieldValues/inc/Module/Install/Base.pm	Thu Mar 12 20:25:44 2009
@@ -1,7 +1,7 @@
 #line 1
 package Module::Install::Base;
 
-$VERSION = '0.70';
+$VERSION = '0.79';
 
 # Suspend handler for "redefined" warnings
 BEGIN {
@@ -45,6 +45,8 @@
     $_[0]->_top->{admin} or Module::Install::Base::FakeAdmin->new;
 }
 
+#line 101
+
 sub is_admin {
     $_[0]->admin->VERSION;
 }
@@ -67,4 +69,4 @@
 
 1;
 
-#line 138
+#line 146

Modified: RT-Extension-ExtractCustomFieldValues/inc/Module/Install/Can.pm
==============================================================================
--- RT-Extension-ExtractCustomFieldValues/inc/Module/Install/Can.pm	(original)
+++ RT-Extension-ExtractCustomFieldValues/inc/Module/Install/Can.pm	Thu Mar 12 20:25:44 2009
@@ -11,7 +11,7 @@
 
 use vars qw{$VERSION $ISCORE @ISA};
 BEGIN {
-	$VERSION = '0.70';
+	$VERSION = '0.79';
 	$ISCORE  = 1;
 	@ISA     = qw{Module::Install::Base};
 }
@@ -39,6 +39,7 @@
 	return $_cmd if (-x $_cmd or $_cmd = MM->maybe_command($_cmd));
 
 	for my $dir ((split /$Config::Config{path_sep}/, $ENV{PATH}), '.') {
+		next if $dir eq '';
 		my $abs = File::Spec->catfile($dir, $_[1]);
 		return $abs if (-x $abs or $abs = MM->maybe_command($abs));
 	}
@@ -79,4 +80,4 @@
 
 __END__
 
-#line 157
+#line 158

Modified: RT-Extension-ExtractCustomFieldValues/inc/Module/Install/Fetch.pm
==============================================================================
--- RT-Extension-ExtractCustomFieldValues/inc/Module/Install/Fetch.pm	(original)
+++ RT-Extension-ExtractCustomFieldValues/inc/Module/Install/Fetch.pm	Thu Mar 12 20:25:44 2009
@@ -6,20 +6,20 @@
 
 use vars qw{$VERSION $ISCORE @ISA};
 BEGIN {
-	$VERSION = '0.70';
+	$VERSION = '0.79';
 	$ISCORE  = 1;
 	@ISA     = qw{Module::Install::Base};
 }
 
 sub get_file {
     my ($self, %args) = @_;
-    my ($scheme, $host, $path, $file) = 
+    my ($scheme, $host, $path, $file) =
         $args{url} =~ m|^(\w+)://([^/]+)(.+)/(.+)| or return;
 
     if ( $scheme eq 'http' and ! eval { require LWP::Simple; 1 } ) {
         $args{url} = $args{ftp_url}
             or (warn("LWP support unavailable!\n"), return);
-        ($scheme, $host, $path, $file) = 
+        ($scheme, $host, $path, $file) =
             $args{url} =~ m|^(\w+)://([^/]+)(.+)/(.+)| or return;
     }
 

Modified: RT-Extension-ExtractCustomFieldValues/inc/Module/Install/Makefile.pm
==============================================================================
--- RT-Extension-ExtractCustomFieldValues/inc/Module/Install/Makefile.pm	(original)
+++ RT-Extension-ExtractCustomFieldValues/inc/Module/Install/Makefile.pm	Thu Mar 12 20:25:44 2009
@@ -7,7 +7,7 @@
 
 use vars qw{$VERSION $ISCORE @ISA};
 BEGIN {
-	$VERSION = '0.70';
+	$VERSION = '0.79';
 	$ISCORE  = 1;
 	@ISA     = qw{Module::Install::Base};
 }
@@ -36,9 +36,9 @@
 
 sub makemaker_args {
 	my $self = shift;
-	my $args = ($self->{makemaker_args} ||= {});
-	  %$args = ( %$args, @_ ) if @_;
-	$args;
+	my $args = ( $self->{makemaker_args} ||= {} );
+	%$args = ( %$args, @_ );
+	return $args;
 }
 
 # For mm args that take multiple space-seperated args,
@@ -63,18 +63,18 @@
 sub clean_files {
 	my $self  = shift;
 	my $clean = $self->makemaker_args->{clean} ||= {};
-	%$clean = (
-		%$clean, 
-		FILES => join(' ', grep length, $clean->{FILES}, @_),
+	  %$clean = (
+		%$clean,
+		FILES => join ' ', grep { length $_ } ($clean->{FILES} || (), @_),
 	);
 }
 
 sub realclean_files {
-	my $self  = shift;
+	my $self      = shift;
 	my $realclean = $self->makemaker_args->{realclean} ||= {};
-	%$realclean = (
-		%$realclean, 
-		FILES => join(' ', grep length, $realclean->{FILES}, @_),
+	  %$realclean = (
+		%$realclean,
+		FILES => join ' ', grep { length $_ } ($realclean->{FILES} || (), @_),
 	);
 }
 
@@ -116,13 +116,19 @@
 
 	# Make sure we have a new enough
 	require ExtUtils::MakeMaker;
-	$self->configure_requires( 'ExtUtils::MakeMaker' => $ExtUtils::MakeMaker::VERSION );
 
-	# Generate the 
+	# MakeMaker can complain about module versions that include
+	# an underscore, even though its own version may contain one!
+	# Hence the funny regexp to get rid of it.  See RT #35800
+	# for details.
+
+	$self->configure_requires( 'ExtUtils::MakeMaker' => $ExtUtils::MakeMaker::VERSION =~ /^(\d+\.\d+)/ );
+
+	# Generate the
 	my $args = $self->makemaker_args;
 	$args->{DISTNAME} = $self->name;
-	$args->{NAME}     = $self->module_name || $self->name || $self->determine_NAME($args);
-	$args->{VERSION}  = $self->version || $self->determine_VERSION($args);
+	$args->{NAME}     = $self->module_name || $self->name;
+	$args->{VERSION}  = $self->version;
 	$args->{NAME}     =~ s/-/::/g;
 	if ( $self->tests ) {
 		$args->{test} = { TESTS => $self->tests };
@@ -175,7 +181,9 @@
 
 	my $user_preop = delete $args{dist}->{PREOP};
 	if (my $preop = $self->admin->preop($user_preop)) {
-		$args{dist} = $preop;
+		foreach my $key ( keys %$preop ) {
+			$args{dist}->{$key} = $preop->{$key};
+		}
 	}
 
 	my $mm = ExtUtils::MakeMaker::WriteMakefile(%args);
@@ -188,7 +196,7 @@
 	my $top_class     = ref($self->_top) || '';
 	my $top_version   = $self->_top->VERSION || '';
 
-	my $preamble = $self->preamble 
+	my $preamble = $self->preamble
 		? "# Preamble by $top_class $top_version\n"
 			. $self->preamble
 		: '';
@@ -242,4 +250,4 @@
 
 __END__
 
-#line 371
+#line 379

Modified: RT-Extension-ExtractCustomFieldValues/inc/Module/Install/Metadata.pm
==============================================================================
--- RT-Extension-ExtractCustomFieldValues/inc/Module/Install/Metadata.pm	(original)
+++ RT-Extension-ExtractCustomFieldValues/inc/Module/Install/Metadata.pm	Thu Mar 12 20:25:44 2009
@@ -6,25 +6,43 @@
 
 use vars qw{$VERSION $ISCORE @ISA};
 BEGIN {
-	$VERSION = '0.70';
+	$VERSION = '0.79';
 	$ISCORE  = 1;
 	@ISA     = qw{Module::Install::Base};
 }
 
 my @scalar_keys = qw{
-	name module_name abstract author version license
-	distribution_type perl_version tests installdirs
+	name
+	module_name
+	abstract
+	author
+	version
+	distribution_type
+	tests
+	installdirs
 };
 
 my @tuple_keys = qw{
-	configure_requires build_requires requires recommends bundles
+	configure_requires
+	build_requires
+	requires
+	recommends
+	bundles
+	resources
 };
 
-sub Meta            { shift        }
-sub Meta_ScalarKeys { @scalar_keys }
-sub Meta_TupleKeys  { @tuple_keys  }
+my @resource_keys = qw{
+	homepage
+	bugtracker
+	repository
+};
+
+sub Meta              { shift          }
+sub Meta_ScalarKeys   { @scalar_keys   }
+sub Meta_TupleKeys    { @tuple_keys    }
+sub Meta_ResourceKeys { @resource_keys }
 
-foreach my $key (@scalar_keys) {
+foreach my $key ( @scalar_keys ) {
 	*$key = sub {
 		my $self = shift;
 		return $self->{values}{$key} if defined wantarray and !@_;
@@ -33,33 +51,65 @@
 	};
 }
 
-foreach my $key (@tuple_keys) {
+foreach my $key ( @resource_keys ) {
 	*$key = sub {
 		my $self = shift;
-		return $self->{values}{$key} unless @_;
+		unless ( @_ ) {
+			return () unless $self->{values}{resources};
+			return map  { $_->[1] }
+			       grep { $_->[0] eq $key }
+			       @{ $self->{values}{resources} };
+		}
+		return $self->{values}{resources}{$key} unless @_;
+		my $uri = shift or die(
+			"Did not provide a value to $key()"
+		);
+		$self->resources( $key => $uri );
+		return 1;
+	};
+}
 
-		my @rv;
-		while (@_) {
-			my $module = shift or last;
+foreach my $key ( grep {$_ ne "resources"} @tuple_keys) {
+	*$key = sub {
+		my $self = shift;
+		return $self->{values}{$key} unless @_;
+		my @added;
+		while ( @_ ) {
+			my $module  = shift or last;
 			my $version = shift || 0;
-			if ( $module eq 'perl' ) {
-				$version =~ s{^(\d+)\.(\d+)\.(\d+)}
-				             {$1 + $2/1_000 + $3/1_000_000}e;
-				$self->perl_version($version);
-				next;
-			}
-			my $rv = [ $module, $version ];
-			push @rv, $rv;
+			push @added, [ $module, $version ];
 		}
-		push @{ $self->{values}{$key} }, @rv;
-		@rv;
+		push @{ $self->{values}{$key} }, @added;
+		return map {@$_} @added;
 	};
 }
 
+# Resource handling
+my %lc_resource = map { $_ => 1 } qw{
+	homepage
+	license
+	bugtracker
+	repository
+};
+
+sub resources {
+	my $self = shift;
+	while ( @_ ) {
+		my $name  = shift or last;
+		my $value = shift or next;
+		if ( $name eq lc $name and ! $lc_resource{$name} ) {
+			die("Unsupported reserved lowercase resource '$name'");
+		}
+		$self->{values}{resources} ||= [];
+		push @{ $self->{values}{resources} }, [ $name, $value ];
+	}
+	$self->{values}{resources};
+}
+
 # Aliases for build_requires that will have alternative
 # meanings in some future version of META.yml.
-sub test_requires      { shift->build_requires(@_)  }
-sub install_requires   { shift->build_requires(@_)  }
+sub test_requires      { shift->build_requires(@_) }
+sub install_requires   { shift->build_requires(@_) }
 
 # Aliases for installdirs options
 sub install_as_core    { $_[0]->installdirs('perl')   }
@@ -69,45 +119,87 @@
 
 sub sign {
 	my $self = shift;
-	return $self->{'values'}{'sign'} if defined wantarray and ! @_;
-	$self->{'values'}{'sign'} = ( @_ ? $_[0] : 1 );
+	return $self->{values}{sign} if defined wantarray and ! @_;
+	$self->{values}{sign} = ( @_ ? $_[0] : 1 );
 	return $self;
 }
 
 sub dynamic_config {
 	my $self = shift;
 	unless ( @_ ) {
-		warn "You MUST provide an explicit true/false value to dynamic_config, skipping\n";
+		warn "You MUST provide an explicit true/false value to dynamic_config\n";
 		return $self;
 	}
-	$self->{'values'}{'dynamic_config'} = $_[0] ? 1 : 0;
-	return $self;
+	$self->{values}{dynamic_config} = $_[0] ? 1 : 0;
+	return 1;
+}
+
+sub perl_version {
+	my $self = shift;
+	return $self->{values}{perl_version} unless @_;
+	my $version = shift or die(
+		"Did not provide a value to perl_version()"
+	);
+
+	# Normalize the version
+	$version = $self->_perl_version($version);
+
+	# We don't support the reall old versions
+	unless ( $version >= 5.005 ) {
+		die "Module::Install only supports 5.005 or newer (use ExtUtils::MakeMaker)\n";
+	}
+
+	$self->{values}{perl_version} = $version;
+}
+
+sub license {
+	my $self = shift;
+	return $self->{values}{license} unless @_;
+	my $license = shift or die(
+		'Did not provide a value to license()'
+	);
+	$self->{values}{license} = $license;
+
+	# Automatically fill in license URLs
+	if ( $license eq 'perl' ) {
+		$self->resources( license => 'http://dev.perl.org/licenses/' );
+	}
+
+	return 1;
 }
 
 sub all_from {
 	my ( $self, $file ) = @_;
 
 	unless ( defined($file) ) {
-		my $name = $self->name
-			or die "all_from called with no args without setting name() first";
+		my $name = $self->name or die(
+			"all_from called with no args without setting name() first"
+		);
 		$file = join('/', 'lib', split(/-/, $name)) . '.pm';
 		$file =~ s{.*/}{} unless -e $file;
-		die "all_from: cannot find $file from $name" unless -e $file;
+		unless ( -e $file ) {
+			die("all_from cannot find $file from $name");
+		}
+	}
+	unless ( -f $file ) {
+		die("The path '$file' does not exist, or is not a file");
 	}
 
+	# Some methods pull from POD instead of code.
+	# If there is a matching .pod, use that instead
+	my $pod = $file;
+	$pod =~ s/\.pm$/.pod/i;
+	$pod = $file unless -e $pod;
+
+	# Pull the different values
+	$self->name_from($file)         unless $self->name;
 	$self->version_from($file)      unless $self->version;
 	$self->perl_version_from($file) unless $self->perl_version;
+	$self->author_from($pod)        unless $self->author;
+	$self->license_from($pod)       unless $self->license;
+	$self->abstract_from($pod)      unless $self->abstract;
 
-	# The remaining probes read from POD sections; if the file
-	# has an accompanying .pod, use that instead
-	my $pod = $file;
-	if ( $pod =~ s/\.pm$/.pod/i and -e $pod ) {
-		$file = $pod;
-	}
-
-	$self->author_from($file)   unless $self->author;
-	$self->license_from($file)  unless $self->license;
-	$self->abstract_from($file) unless $self->abstract;
+	return 1;
 }
 
 sub provides {
@@ -169,8 +261,8 @@
 	while ( my ( $name, $mods ) = splice( @_, 0, 2 ) ) {
 		$self->feature( $name, @$mods );
 	}
-	return $self->{values}->{features}
-		? @{ $self->{values}->{features} }
+	return $self->{values}{features}
+		? @{ $self->{values}{features} }
 		: ();
 }
 
@@ -183,10 +275,10 @@
 
 sub read {
 	my $self = shift;
-	$self->include_deps( 'YAML', 0 );
+	$self->include_deps( 'YAML::Tiny', 0 );
 
-	require YAML;
-	my $data = YAML::LoadFile('META.yml');
+	require YAML::Tiny;
+	my $data = YAML::Tiny::LoadFile('META.yml');
 
 	# Call methods explicitly in case user has already set some values.
 	while ( my ( $key, $value ) = each %$data ) {
@@ -226,35 +318,51 @@
 	 );
 }
 
-sub _slurp {
-	local *FH;
-	open FH, "< $_[1]" or die "Cannot open $_[1].pod: $!";
-	do { local $/; <FH> };
+# Add both distribution and module name
+sub name_from {
+	my ($self, $file) = @_;
+	if (
+		Module::Install::_read($file) =~ m/
+		^ \s*
+		package \s*
+		([\w:]+)
+		\s* ;
+		/ixms
+	) {
+		my ($name, $module_name) = ($1, $1);
+		$name =~ s{::}{-}g;
+		$self->name($name);
+		unless ( $self->module_name ) {
+			$self->module_name($module_name);
+		}
+	} else {
+		die("Cannot determine name from $file\n");
+	}
 }
 
 sub perl_version_from {
-	my ( $self, $file ) = @_;
+	my $self = shift;
 	if (
-		$self->_slurp($file) =~ m/
+		Module::Install::_read($_[0]) =~ m/
 		^
-		use \s*
+		(?:use|require) \s*
 		v?
 		([\d_\.]+)
 		\s* ;
 		/ixms
 	) {
-		my $v = $1;
-		$v =~ s{_}{}g;
-		$self->perl_version($1);
+		my $perl_version = $1;
+		$perl_version =~ s{_}{}g;
+		$self->perl_version($perl_version);
 	} else {
-		warn "Cannot determine perl version info from $file\n";
+		warn "Cannot determine perl version info from $_[0]\n";
 		return;
 	}
 }
 
 sub author_from {
-	my ( $self, $file ) = @_;
-	my $content = $self->_slurp($file);
+	my $self    = shift;
+	my $content = Module::Install::_read($_[0]);
 	if ($content =~ m/
 		=head \d \s+ (?:authors?)\b \s*
 		([^\n]*)
@@ -268,15 +376,14 @@
 		$author =~ s{E<gt>}{>}g;
 		$self->author($author);
 	} else {
-		warn "Cannot determine author info from $file\n";
+		warn "Cannot determine author info from $_[0]\n";
 	}
 }
 
 sub license_from {
-	my ( $self, $file ) = @_;
-
+	my $self = shift;
 	if (
-		$self->_slurp($file) =~ m/
+		Module::Install::_read($_[0]) =~ m/
 		(
 			=head \d \s+
 			(?:licen[cs]e|licensing|copyright|legal)\b
@@ -288,8 +395,12 @@
 		my $license_text = $1;
 		my @phrases      = (
 			'under the same (?:terms|license) as perl itself' => 'perl',        1,
+			'GNU general public license'                      => 'gpl',         1,
 			'GNU public license'                              => 'gpl',         1,
+			'GNU lesser general public license'               => 'lgpl',        1,
 			'GNU lesser public license'                       => 'lgpl',        1,
+			'GNU library general public license'              => 'lgpl',        1,
+			'GNU library public license'                      => 'lgpl',        1,
 			'BSD license'                                     => 'bsd',         1,
 			'Artistic license'                                => 'artistic',    1,
 			'GPL'                                             => 'gpl',         1,
@@ -302,17 +413,98 @@
 		while ( my ($pattern, $license, $osi) = splice(@phrases, 0, 3) ) {
 			$pattern =~ s{\s+}{\\s+}g;
 			if ( $license_text =~ /\b$pattern\b/i ) {
-				if ( $osi and $license_text =~ /All rights reserved/i ) {
-					warn "LEGAL WARNING: 'All rights reserved' may invalidate Open Source licenses. Consider removing it.";
-				}
 				$self->license($license);
 				return 1;
 			}
 		}
 	}
 
-	warn "Cannot determine license info from $file\n";
+	warn "Cannot determine license info from $_[0]\n";
 	return 'unknown';
 }
 
+sub bugtracker_from {
+	my $self    = shift;
+	my $content = Module::Install::_read($_[0]);
+	my @links   = $content =~ m/L\<(http\:\/\/rt\.cpan\.org\/[^>]+)\>/g;
+	unless ( @links ) {
+		warn "Cannot determine bugtracker info from $_[0]\n";
+		return 0;
+	}
+	if ( @links > 1 ) {
+		warn "Found more than on rt.cpan.org link in $_[0]\n";
+		return 0;
+	}
+
+	# Set the bugtracker
+	bugtracker( $links[0] );
+	return 1;
+}
+
+# Convert triple-part versions (eg, 5.6.1 or 5.8.9) to
+# numbers (eg, 5.006001 or 5.008009).
+# Also, convert double-part versions (eg, 5.8)
+sub _perl_version {
+	my $v = $_[-1];
+	$v =~ s/^([1-9])\.([1-9]\d?\d?)$/sprintf("%d.%03d",$1,$2)/e;	
+	$v =~ s/^([1-9])\.([1-9]\d?\d?)\.(0|[1-9]\d?\d?)$/sprintf("%d.%03d%03d",$1,$2,$3 || 0)/e;
+	$v =~ s/(\.\d\d\d)000$/$1/;
+	$v =~ s/_.+$//;
+	if ( ref($v) ) {
+		$v = $v + 0; # Numify
+	}
+	return $v;
+}
+
+
+
+
+
+######################################################################
+# MYMETA.yml Support
+
+sub WriteMyMeta {
+	$_[0]->write_mymeta;
+}
+
+sub write_mymeta {
+	my $self = shift;
+	
+	# If there's no existing META.yml there is nothing we can do
+	return unless -f 'META.yml';
+
+	# Merge the perl version into the dependencies
+	my $val  = $self->Meta->{values};
+	my $perl = delete $val->{perl_version};
+	if ( $perl ) {
+		$val->{requires} ||= [];
+		my $requires = $val->{requires};
+
+		# Canonize to three-dot version after Perl 5.6
+		if ( $perl >= 5.006 ) {
+			$perl =~ s{^(\d+)\.(\d\d\d)(\d*)}{join('.', $1, int($2||0), int($3||0))}e
+		}
+		unshift @$requires, [ perl => $perl ];
+	}
+
+	# Load the advisory META.yml file
+	require YAML::Tiny;
+	my @yaml = YAML::Tiny::LoadFile('META.yml');
+	my $meta = $yaml[0];
+
+	# Overwrite the non-configure dependency hashs
+	delete $meta->{requires};
+	delete $meta->{build_requires};
+	delete $meta->{recommends};
+	if ( exists $val->{requires} ) {
+		$meta->{requires} = { map { @$_ } @{ $val->{requires} } };
+	}
+	if ( exists $val->{build_requires} ) {
+		$meta->{build_requires} = { map { @$_ } @{ $val->{build_requires} } };
+	}
+
+	# Save as the MYMETA.yml file
+	YAML::Tiny::DumpFile('MYMETA.yml', $meta);
+}
+
 1;

Modified: RT-Extension-ExtractCustomFieldValues/inc/Module/Install/Win32.pm
==============================================================================
--- RT-Extension-ExtractCustomFieldValues/inc/Module/Install/Win32.pm	(original)
+++ RT-Extension-ExtractCustomFieldValues/inc/Module/Install/Win32.pm	Thu Mar 12 20:25:44 2009
@@ -6,7 +6,7 @@
 
 use vars qw{$VERSION @ISA $ISCORE};
 BEGIN {
-	$VERSION = '0.70';
+	$VERSION = '0.79';
 	@ISA     = qw{Module::Install::Base};
 	$ISCORE  = 1;
 }

Modified: RT-Extension-ExtractCustomFieldValues/inc/Module/Install/WriteAll.pm
==============================================================================
--- RT-Extension-ExtractCustomFieldValues/inc/Module/Install/WriteAll.pm	(original)
+++ RT-Extension-ExtractCustomFieldValues/inc/Module/Install/WriteAll.pm	Thu Mar 12 20:25:44 2009
@@ -6,7 +6,7 @@
 
 use vars qw{$VERSION @ISA $ISCORE};
 BEGIN {
-	$VERSION = '0.70';
+	$VERSION = '0.79';
 	@ISA     = qw{Module::Install::Base};
 	$ISCORE  = 1;
 }

Modified: RT-Extension-ExtractCustomFieldValues/lib/RT/Action/ExtractCustomFieldValues.pm
==============================================================================
--- RT-Extension-ExtractCustomFieldValues/lib/RT/Action/ExtractCustomFieldValues.pm	(original)
+++ RT-Extension-ExtractCustomFieldValues/lib/RT/Action/ExtractCustomFieldValues.pm	Thu Mar 12 20:25:44 2009
@@ -6,7 +6,7 @@
 
 use base qw(RT::Action::Generic);
 
-our $VERSION = 2.05;
+our $VERSION = 2.99_01;
 
 sub Describe {
     my $self = shift;
@@ -17,18 +17,22 @@
     return (1);
 }
 
-sub Commit {
-    my $self            = shift;
-    my $Transaction     = $self->TransactionObj;
-    my $FirstAttachment = $Transaction->Attachments->First;
-    unless ($FirstAttachment) { return 1; }
-
-    my $Ticket    = $self->TicketObj;
-    my $Content   = $self->TemplateObj->Content;
-    my $Queue     = $Ticket->QueueObj->Id;
-    my $Separator = '\|';
+sub FirstAttachment {
+    my $self = shift;
+    return $self->TransactionObj->Attachments->First;
+}
+
+sub Queue {
+    my $self = shift;
+    return $self->TicketObj->QueueObj->Id;
+}
+
+sub TemplateConfig {
+    my $self = shift;
 
-    my @lines = split( /[\n\r]+/, $Content );
+    my $Separator = '\|';
+    my @lines = split( /[\n\r]+/, $self->TemplateObj->Content );
+    my @results;
     for (@lines) {
         chomp;
         next if (/^#/);
@@ -37,145 +41,141 @@
             $Separator = $1;
             next;
         }
-        my ( $CustomFieldName, $InspectField, $MatchString, $PostEdit,
-            $Options )
+        my %line;
+        @line{qw/CFName Field Match PostEdit Options/}
             = split(/$Separator/);
+        push @results, \%line;
+    }
+    return @results;
+}
 
-        if ( $Options =~ /\*/ ) {
-            ProcessWildCard(
-                Field       => $InspectField,
-                Match       => $MatchString,
-                PostEdit    => $PostEdit,
-                Attachment  => $FirstAttachment,
-                Queue       => $Queue,
-                Ticket      => $Ticket,
-                Transaction => $Transaction,
-                Options     => $Options,
-            );
-            next;
-        }
-
-        my $cf;
-        if ($CustomFieldName) {
-            $cf = LoadCF( Field => $CustomFieldName, Queue => $Queue );
-        }
-
-        my $match = FindMatch(
-            Field           => $InspectField,
-            Match           => $MatchString,
-            FirstAttachment => $FirstAttachment,
-        );
-
-        my %processing_args = (
-            CustomField => $cf,
-            Match       => $match,
-
-            Ticket      => $Ticket,
-            Transaction => $Transaction,
-            Attachment  => $FirstAttachment,
-
-            PostEdit => $PostEdit,
-            Options  => $Options,
-        );
+sub Commit {
+    my $self            = shift;
+    return 1 unless $self->FirstAttachment;
 
-        if ($cf) {
-            ProcessCF(%processing_args);
+    for my $config ($self->TemplateConfig) {
+        require YAML;
+        $RT::Logger->debug("Looking to extract:" . YAML::Dump($config));
+        
+        my %config = %{$config};
+
+        if ( $config{Options} =~ /\*/ ) {
+            $self->FindContent(
+                %config,
+                Callback    => sub {
+                    my $content = shift;
+                    while ( $content =~ /$config{Match}/mg ) {
+                        my ( $cf, $value ) = ( $1, $2 );
+                        $cf = $self->LoadCF( Name => $cf, Quiet => 1 );
+                        next unless $cf;
+                        $self->ProcessCF(
+                            %config,
+                            CustomField => $cf,
+                            Value       => $value
+                        );
+                    }
+                },
+            );
         } else {
-            ProcessMatch(%processing_args);
+            my $cf;
+            $cf = $self->LoadCF( Name => $config{CFName} )
+                if $config{CFName};
+
+            $self->FindContent(
+                %config,
+                Callback    => sub {
+                    my $content = shift;
+                    my $value = $1 || $& if $content =~ /$config{Match}/m;
+                    $self->ProcessCF(
+                        %config,
+                        CustomField => $cf,
+                        Value       => $value,
+                    );
+                }
+            );
         }
     }
     return (1);
 }
 
 sub LoadCF {
+    my $self = shift;
     my %args            = @_;
-    my $CustomFieldName = $args{Field};
-    my $Queue           = $args{Queue};
-    $RT::Logger->debug("load cf $CustomFieldName");
+    my $CustomFieldName = $args{Name};
+    $RT::Logger->debug( "Looking for CF $CustomFieldName");
 
     # We do this by hand instead of using LoadByNameAndQueue because
     # that can find disabled queues
     my $cfs = RT::CustomFields->new($RT::SystemUser);
-    $cfs->LimitToGlobalOrQueue( $Queue );
-    $cfs->Limit( FIELD => 'Name', VALUE => $CustomFieldName, CASESENSITIVE => 0);
+    $cfs->LimitToGlobalOrQueue($self->Queue);
+    $cfs->Limit(
+        FIELD         => 'Name',
+        VALUE         => $CustomFieldName,
+        CASESENSITIVE => 0
+    );
     $cfs->RowsPerPage(1);
 
     my $cf = $cfs->First;
     if ( $cf->id ) {
-        $RT::Logger->debug( "load cf done: " . $cf->id );
+        $RT::Logger->debug( "Found CF id " . $cf->id );
     } elsif ( not $args{Quiet} ) {
-        $RT::Logger->error("couldn't load cf $CustomFieldName");
+        $RT::Logger->error( "Couldn't load CF $CustomFieldName!");
     }
 
     return $cf;
 }
 
-sub ProcessWildCard {
-    my %args = @_;
-
-    my $content
-        = lc $args{Field} eq "body"
-        ? $args{Attachment}->Content
-        : $args{Attachment}->GetHeader( $args{Field} );
-    return unless defined $content;
-    while ( $content =~ /$args{Match}/mg ) {
-        my ( $cf, $value ) = ( $1, $2 );
-        $cf = LoadCF( Field => $cf, Queue => $args{Queue}, Quiet => 1 );
-        next unless $cf;
-        ProcessCF(
-            %args,
-            CustomField => $cf,
-            Match       => $value
-        );
-    }
-}
-
-sub FindMatch {
+sub FindContent {
+    my $self = shift;
     my %args = @_;
-
-    my $match = '';
-    if ( $args{Field} =~ /^body$/i ) {
-        $RT::Logger->debug("look for match in Body");
-        if (   $args{FirstAttachment}->Content
-            && $args{FirstAttachment}->Content =~ /$args{Match}/m )
-        {
-            $match = $1 || $&;
-            $RT::Logger->debug("matched value: $match");
+    if ( lc $args{Field} eq "body" ) {
+        my $Attachments  = $self->TransactionObj->Attachments;
+        my $LastContent  = '';
+        my $AttachmentCount = 0;
+
+        while ( my $Message = $Attachments->Next ) {
+            $AttachmentCount++;
+            $RT::Logger->debug( "Looking at attachment $AttachmentCount, content-type "
+                                    . $Message->ContentType );
+            next
+                unless $Message->ContentType
+                    =~ m!^(text/plain|message|text$)!i;
+            next unless $Message->Content;
+            next if $LastContent eq $Message->Content;
+            $RT::Logger->debug( "Examining content of body" );
+            $LastContent = $Message->Content;
+            $args{Callback}->( $Message->Content )
         }
     } else {
-        $RT::Logger->debug("look for match in Header $args{Field}");
-        if ( $args{FirstAttachment}->GetHeader("$args{Field}")
-            =~ /$args{Match}/ )
-        {
-            $match = $1 || $&;
-            $RT::Logger->debug("matched value: $match");
-        }
+        my $attachment = $self->FirstAttachment;
+        $RT::Logger->debug( "Looking at $args{Field} header of first attachment" );
+        my $content = $attachment->GetHeader( $args{Field} );
+        return unless defined $content;
+        $RT::Logger->debug( "Examining content of header" );
+        $args{Callback}->( $content );
     }
-
-    return $match;
 }
 
 sub ProcessCF {
+    my $self = shift;
     my %args = @_;
 
+    return $self->PostEdit(%args)
+        unless $args{CustomField};
+
     my @values = ();
     if ( $args{CustomField}->SingleValue() ) {
-        push @values, $args{Match};
+        push @values, $args{Value};
     } else {
-        @values = split( ',', $args{Match} );
+        @values = split( ',', $args{Value} );
     }
 
     foreach my $value ( grep defined && length, @values ) {
-        if ( $args{PostEdit} ) {
-            local $@;
-            eval( $args{PostEdit} );
-            $RT::Logger->error("$@") if $@;
-            $RT::Logger->debug("transformed ($args{PostEdit}) value: $value");
-        }
+        $value = $self->PostEdit(%args, Value => $value );
         next unless defined $value && length $value;
 
-        $RT::Logger->debug("found value for cf: $value");
-        my ( $id, $msg ) = $args{Ticket}->AddCustomFieldValue(
+        $RT::Logger->debug( "Found value for CF: $value");
+        my ( $id, $msg ) = $self->TicketObj->AddCustomFieldValue(
             Field             => $args{CustomField},
             Value             => $value,
             RecordTransaction => $args{Options} =~ /q/ ? 0 : 1
@@ -186,19 +186,19 @@
     }
 }
 
-sub ProcessMatch {
-    my %args            = @_;
-    my $Ticket          = $args{Ticket};
-    my $Transaction     = $args{Transaction};
-    my $FirstAttachment = $args{Attachment};
-
-    if ( $args{Match} && $args{PostEdit} ) {
-        local $_ = $args{Match};    # backwards compatibility
-        local $@;
-        eval( $args{PostEdit} );
-        $RT::Logger->error("$@") if $@;
-        $RT::Logger->debug("ran code $args{PostEdit} $@");
-    }
+sub PostEdit {
+    my $self = shift;
+    my %args = @_;
+
+    return $args{Value} unless $args{Value} && $args{PostEdit};
+
+    $RT::Logger->debug( "Running PostEdit for '$args{Value}'");
+    my $value = $args{Value};
+    local $_  = $value;    # backwards compatibility
+    local $@;
+    eval( $args{PostEdit} );
+    $RT::Logger->error("$@") if $@;
+    return $value;
 }
 
 1;

Modified: RT-Extension-ExtractCustomFieldValues/lib/RT/Extension/ExtractCustomFieldValues.pm
==============================================================================
--- RT-Extension-ExtractCustomFieldValues/lib/RT/Extension/ExtractCustomFieldValues.pm	(original)
+++ RT-Extension-ExtractCustomFieldValues/lib/RT/Extension/ExtractCustomFieldValues.pm	Thu Mar 12 20:25:44 2009
@@ -3,6 +3,6 @@
 
 package RT::Extension::ExtractCustomFieldValues;
 
-our $VERSION = '2.05';
+our $VERSION = '2.99_01';
 
 1;



More information about the Bps-public-commit mailing list