Debian-Apt-PM

 view release on metacpan or  search on metacpan

script/dpkg-scanpmpackages  view on Meta::CPAN

	#       this could be done probably based on a --perl-folders-only switch
	
	# find all package names from pm_files
	foreach my $pm_file (@pm_files) {
		# add version 0 based on filename, will be set properly later if found
		if (my $inc_prefix = firstval { index($pm_file, $tmp_dir.$_) == 0 } @INC) {
			$inc_prefix = $tmp_dir.$inc_prefix;
			my $package = substr($pm_file, length($inc_prefix)+1, -3);
			$package =~ s{/}{::}xmsg;
			$provides{$package} = 0;
		}

		# get module info
		my $info = eval { Module::Build::ModuleInfo->new_from_file($pm_file) };
		warn 'failed to get module info of "'.$pm_file.'" - "'.$@.'"' if $@;
		next if not $info;
		
		#print 'processing ', $pm_file, "\n";
		
		$pm_file =~ s{^$tmp_dir.(.+)$}{$1};
		
		foreach my $package (keys %{$info->{'versions'}}) {
			next if $package eq 'main';
			
			# skip inside packages
			my $package_file = $package.'.pm';
			$package_file =~ s{::}{/}xmsg;
			next if substr($pm_file,0-length($package_file)) ne $package_file;
			
			# set version to undef 
			my $version = (
				$info->{'versions'}->{$package}
				? $info->{'versions'}->{$package}->stringify
				: 0
			);
			
			$provides{$package} = $version;
		}
	}
	
	remove_tree($tmp_dir);
	unlink($deb_full_filename)
		if $cleanup_deb;
	
	return %provides;	
}

sub fetch {
	my $url      = shift;
	my $filename = shift;
	
	my $ua = LWP::UserAgent->new;
	$ua->timeout(10);
	$ua->env_proxy;
	 
	my $response = $ua->get($url);
	
	die 'failed to fetch '.$url.' - '.$response->status_line
		if (not $response->is_success);
	
	IO::Any->spew([ $filename ], $response->decoded_content);
	
	return;
}

sub _trim {
	my $text = shift;
	croak 'too much argauments' if @_;
	
	return
		unless defined $text;
	
	$text =~ s/^\s+//xms;
	$text =~ s/\s+$//xms;
	
	return $text;
}

sub print_version {
	print "$0 $VERSION\n";
	exit 0;
}

__END__

=head1 NAME

dpkg-scanpmpackages - creates PerlPackages index from .deb files

=head1 SYNOPSIS

	dpkg-scanpmpackages [repository_folder]
	
		--blacklist=comma,separated,package,names
			optional - packages that should not be indexed
		--pool-url=http://ftp.cz.debian.org/debian/
		    optional - an url to fetch missing .deb files from
		--cleanup-deb
		    optional - when set will remove .deb file after it was processed

=head1 DESCRIPTION

Finds all F<Packages.bz2> and for all F<*.deb> files listed there indexes
the Perl modules files F<*.pm> creating F<PerlPackages.bz2> file in the same
folder.

=head1 AUTHOR

Jozef Kutej

=head1 COPYRIGHT

This program is free software; you can redistribute it and/or
modify it under the same terms as Perl itself.

=cut



( run in 2.374 seconds using v1.01-cache-2.11-cpan-98e64b0badf )