Paralle...::Child(3)

πŸ¦‹ Parallel::ForkManager::Child β€” the role your forked kids grow into

So this is a page from the User Contributed Perl Documentation for Parallel::ForkManager::Child, and honestly? It's a little baddie of a module. Let's get into it πŸ’…

✨ NAME ✨

Parallel::ForkManager::Child β€” the role adopted by forked Parallel::ForkManager processes. Like, the parent makes a whole new process and that baby straight up becomes this role. Main character energy, fr fr πŸ‘‘

🌸 VERSION 🌸

version 2.03 β€” noted, locked in, no cap.

πŸŽ€ SYNOPSIS πŸŽ€

Okay bestie, here's the whole vibe in code:

use 5.10.0;

use Parallel::ForkManager;

my $fm = Parallel::ForkManager->new;

say "parent does not consume the child role: ", $fm->does('Parallel::ForkManager::Child');

$fm->start_child(sub{
     sleep $_;
     say "but the child does: ", $fm->does('Parallel::ForkManager::Child');
     say "child $_ says hi!"

}) for 1..3;

See what's happening? The parent checks does('Parallel::ForkManager::Child') and it's a whole no β€” the parent does not consume the child role. But the moment it forks, the child totally does. The way that's the entire plot 😭

πŸ’– DESCRIPTION πŸ’–

So here's the tea β˜• β€” when the parent Parallel::ForkManager object forks a child process, that forked incarnation consumes this role. That's it, that's the whole thing.

And the role doesn't do much, ngl. It's lowkey just three little glow-ups:

  • it changes the returning values of is_child and is_parent in exactly the way you'd expect (like, obviously πŸ’€),
  • it changes start so that it would die if it got called from within the child β€” no sneaky nesting, bestie,
  • and it changes the implementation of finish so it can potentially send data back to the parent process. Cute, functional, iconic 🫢

🌈 AUTHORS 🌈

Shoutout to the actual legends who built this:

  • dLux (SzabΓ³, BalΓ‘zs) <dlux@dlux.hu>
  • Yanick Champoux <yanick@cpan.org>
  • Gabor Szabo <gabor@szabgab.com>

This software is copyright (c) 2024, 2015 by BalΓ‘zs SzabΓ³.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. So like, go off, remix it, it's yours πŸ“


Real talk for a sec: if you're poking at Parallel::ForkManager::Child and wondering why is_child flips the way it does β€” that's the role doing its one job. Don't fight it, bestie πŸ’œ

And that's a wrap! This page came to you courtesy of perl v5.42.0, dated 2024-09-01, living its best life as Parallel::ForkManager::Child(3) in the User Contributed Perl Documentation. Slay, stay forked, and hydrate ✨🧚

πŸ“¦ where this page comes from