Carrot

 view release on metacpan or  search on metacpan

lib/Carrot/Individuality/Singular/Process/Id.pm  view on Meta::CPAN


	my $expressiveness = Carrot::individuality;
	$expressiveness->provide(
#FIXME: result of a blind conversion - looks not correct
		my $local_episode_class = '::Continuity::Coordination::Episode::Local',
		my $distinguished_exceptions = '::Individuality::Controlled::Distinguished_Exceptions');
	#	my $kindergarden = '::Individuality::Singular::Process::Kindergarden');

#FIXME:
	$distinguished_exceptions->provide(
		my $perl_fork_failed = 'perl_fork_failed',
		my $perl_setxid_failed = 'perl_setxid_failed');

	my $local_subscription = $local_episode->indirect_constructor;
	$local_subscription->register_event('pid_change');

	$expressiveness->declare_provider;

# =--------------------------------------------------------------------------= #

sub attribute_construction
# /type method
# /effect "Constructs the attribute(s) of a newly created instance."
# //parameters
#	value  ::Personality::Abstract::Number
# //returns
{
	my ($this) = @ARGUMENTS;

	$$this = (exists($_[SPX_PID]) ? $_[SPX_PID] : $PROCESS_PID);
	return;
}

sub subscribe_pid_change
# /type method
# /effect ""
# //parameters
#	instance  +multiple
# //returns
{
	my $this = shift(\@ARGUMENTS);

	$local_subscription->subscribe('pid_change', @ARGUMENTS);
	return;
}

sub unsubscribe_pid_change
# /type method
# /effect ""
# //parameters
#	instance  +multiple
# //returns
{
	my $this = shift(\@ARGUMENTS);

	$local_subscription->unsubscribe('pid_change', @ARGUMENTS);
	return;
}


sub update
# /type method
# /effect ""
# //parameters
# //returns
{
	return if (${$_[THIS]} == $PROCESS_PID);
	${$_[THIS]} = $PROCESS_ID;
	$local_subscription->trigger_event('pid_change');
	return;
}

sub fork
# /type method
# /effect ""
# //parameters
# //returns
#	?
{
	my $parent_pid = $PROCESS_ID;

	#FIXME: use $fatal_syscalls
	my $child_pid = CORE::fork();
	unless (defined($child_pid))
	{
		$perl_fork_failed->raise_exception(
			{'pid' => $PROCESS_ID,
			 'name' => $PROGRAM_NAME,
			 'os_error' => $OS_ERROR},
			ERROR_CATEGORY_OS);
	}

	if ($child_pid > 0)
	{
		return($child_pid);
	} else {
		$_[THIS]->update;
		return(-$parent_pid);
	}
}

sub set_name
# /type method
# /effect ""
# //parameters
#	name
# //returns
{
	$PROGRAM_NAME = $_[SPX_NAME];
	return;
}
sub get_name
# /type function
# /effect ""
# //parameters
# //returns
#	?
{
	return($PROGRAM_NAME);
}



( run in 1.137 second using v1.01-cache-2.11-cpan-5a3173703d6 )