LogoopenSUSE Build Service > Projects
Sign Up | Log In

View File perl-Parallel-ForkManager.spec of Package perl-Parallel-ForkManager (Project home:csbuild:Perl)

#   - Parallel::ForkManager -
#   This spec file was automatically generated by cpan2rpm [ver: 2.028]
#   The following arguments were used:
#       Parallel-ForkManager-0.7.5.tar.gz
#   For more information on cpan2rpm please visit: http://perl.arix.com/

%define real_name Parallel-ForkManager
%define perl_vendorlib %(eval "`perl -V:installvendorlib`"; echo $installvendorlib)
%define perl_vendorarch %(eval "`perl -V:installvendorarch`"; echo $installvendorarch)
%define perl_archlib %(eval "`perl -V:archlib`"; echo $archlib)
%define perl_privlib %(eval "`perl -V:privlib`"; echo $privlib)
%define maketest 0

Name:           perl-%{real_name}
Summary:   	Parallel-ForkManager - A simple parallel processing fork manager
Version:   	0.7.5
Release:   	1
Url:       	http://www.cpan.org
Source:    	http://search.cpan.org/CPAN/authors/id/D/DL/DLUX/%{real_name}-%{version}.tar.gz
License:   	Artistic
Group:          Development/Libraries/Perl
AutoReqProv:    on
buildroot: 	%{_tmppath}/%{name}-%{version}-%(id -u -n)
buildarch: 	noarch

BuildRequires:  perl

This module is intended for use in operations that can be done in parallel 
where the number of processes to be forked off should be limited. Typical 
use is a downloader which will be retrieving hundreds/thousands of files.

The code for a downloader would look something like this:

  use LWP::Simple;
  use Parallel::ForkManager;



  # Max 30 processes for parallel download
  my $pm = new Parallel::ForkManager(30); 

  foreach my $linkarray (@links) {
    $pm->start and next; # do the fork

    my ($link,$fn) = @$linkarray;
    warn "Cannot get $fn from $link"
      if getstore($link,$fn) != RC_OK;

    $pm->finish; # do the exit in the child process

First you need to instantiate the ForkManager with the "new" constructor. 
You must specify the maximum number of processes to be created. If you 
specify 0, then NO fork will be done; this is good for debugging purposes.

Next, use $pm->start to do the fork. $pm returns 0 for the child process, 
and child pid for the parent process (see also "fork()" in perlfunc(1p)). 
The "and next" skips the internal loop in the parent process. NOTE: 
$pm->start dies if the fork fails.

$pm->finish terminates the child process (assuming a fork was done in the 

NOTE: You cannot use $pm->start if you are already in the child process. 
If you want to manage another set of subprocesses in the child process, 
you must instantiate another Parallel::ForkManager object!

%setup -q -n %{real_name}-%{version}
chmod -R u+w %{_builddir}/%{real_name}-%{version}

[ "%{buildroot}" != "/" ] && rm -rf %{buildroot}

%{__perl} Makefile.PL `%{__perl} -MExtUtils::MakeMaker -e ' print qq|PREFIX=%{buildroot}%{_prefix}| if \$ExtUtils::MakeMaker::VERSION =~ /5\.
9[1-6]|6\.0[0-5]/ '`

%if %maketest
%{__make} test

%if 0%{?suse_version}
make DESTDIR=$RPM_BUILD_ROOT install_vendor
find $RPM_BUILD_ROOT/usr -type f -name perllocal.pod |xargs -i rm -f {}
find $RPM_BUILD_ROOT/usr -type d -depth -exec rmdir {} \; 2>/dev/null
find %{buildroot} -name "perllocal.pod" -o -name ".packlist" -o -name "*.bs" |xargs -i rm -f {}

%defattr(-, root, root)
%doc Changes TODO
%doc %{_mandir}/man?/*
%dir %{perl_vendorlib}/Parallel
%dir %{perl_vendorlib}/Parallel/ForkManager
%if 0%{?suse_version}

* Fri Feb 26 2010 Holger Manthey <holger.manthey@bertelsmann.de>
- Initial build.