Carrot

 view release on metacpan or  search on metacpan

lib/Carrot/Individuality/Controlled/Customized_Settings/Monad.pm  view on Meta::CPAN

package Carrot::Individuality::Controlled::Customized_Settings::Monad
# /type class
# /attribute_type ::Many_Declared::Ordered
# //parameters
#	inheritance  ::Modularity::Object::Inheritance::ISA_Occupancy
# /capability ""
{
	my ($inheritance) = @ARGUMENTS;

	use strict;
	use warnings 'FATAL' => 'all';

	my $expressiveness = Carrot::individuality;
	$expressiveness->provide(
		'::Individuality::Controlled::',
			my $class_names = '::Class_Names',
			my $distinguished_exceptions = '::Distinguished_Exceptions');

	$class_names->provide(
		my $cursor_class = '::Personality::Reflective::Iterate::Array::Cursor',
		'[=project_pkg=]::',
			my $line_class = '::Dot_Cfg::Line',
			my $source_class = '::Source::Here::Plain',
			my $dot_cdf_class = '::Dot_Cdf');

	$class_names->provide_instance(
		my $writable_overlay = '::Meta::Greenhouse::Writable_Overlay',
		my $compilation_name = '::Meta::Greenhouse::Compilation_Name');

	$distinguished_exceptions->provide(
		my $unsupported_data_type = 'unsupported_data_type',
		my $hash_element_missing = 'hash_element_missing');

	Carrot::Meta::Greenhouse::Package_Loader::provide_instance(
		my $loader = '::Modularity::Package::Loader');

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

sub attribute_construction
# /type method
# /effect "Constructs the attribute(s) of a newly created instance."
# //parameters
#	meta_monad  ::Meta::Monad
# //returns
{
	my ($this, $meta_monad) = @ARGUMENTS;

	my $package_file = $meta_monad->package_file;
	my $dot_directory = $package_file->dot_directory;
	my $default_settings = $dot_directory->entry('default_settings.cdf');
	$default_settings->consider_regular_content;

	my $compiled_settings = $dot_directory->entry(
		"default_settings-$$compilation_name.pl");
	$writable_overlay->redirect_read($compiled_settings);
	if ($default_settings->modification_timestamp_is_newer($compiled_settings))
	{
	# NOTE: manually setting @ARGUMENTS copies but doesn't alias them
		@ARGUMENTS = ($loader, \$this->[ATR_VALUES]);
		require($compiled_settings->value);
		$this->[ATR_ARE_MODIFIED] = IS_FALSE;
		return;
	}
	$this->[ATR_ARE_MODIFIED] = IS_TRUE;

	my $these_values = $this->[ATR_VALUES] = {};

	my $dot_cdf = $dot_cdf_class->indirect_constructor(
		$meta_monad->class_names,
		$default_settings);
##	$this->[ATR_DEFINER] = $dot_cdf;
	$dot_cdf->definition($these_values);

	my $independent = IS_TRUE;
	my $occupied = $inheritance->collect_occupied(
		$meta_monad->parent_classes->perl_isa);
	foreach my $that (reverse(@$occupied))
	{
		my $those_values = $that->[ATR_VALUES];
#FIXME: the behaviour should be documented - different from ->inherit

lib/Carrot/Individuality/Controlled/Customized_Settings/Monad.pm  view on Meta::CPAN

#	return unless (defined($file_name));

	$_[SPX_FILE_NAME]->consider_regular_content;
	$_[SPX_FILE_NAME]->read_into(my $buffer);
	$_[THIS]->customize_by_scalar($buffer);
	return;
}

sub clone_plus_scalarref
# /type method
# /effect ""
# //parameters
#	buffer
# //returns
#	?
{
	my $clone = $_[THIS]->clone_constructor;
	$clone->customize_by_scalar(${$_[SPX_BUFFER]});
	return($clone);
}

sub customize_by_scalar
# /type method
# /effect ""
# //parameters
#	buffer
# //returns
{
	$_[SPX_BUFFER] =~ s{\s+$}{}s;
	my $lines = [split(
		qr{(?:\012|\015\012?)},
		$_[SPX_BUFFER],
		PKY_SPLIT_IGNORE_EMPTY_TRAIL)];
	$_[THIS]->customize_by_arrayref($lines);
	return;
}

sub clone_plus_arrayref
# /type method
# /effect ""
# //parameters
#	buffer
# //returns
#	?
{
	my $clone = $_[THIS]->clone_constructor;
	$clone->customize_by_arrayref($_[SPX_BUFFER]);
	return($clone);
}

sub customize_by_arrayref
# /type method
# /effect ""
# //parameters
#	lines
# //returns
{
	my ($this, $lines) = @ARGUMENTS;

	my $line = $line_class->indirect_constructor;
	my $cursor = $cursor_class->indirect_constructor($lines, $line);

	my $count = 0;
	my ($setting, $source);
	my $anchor1 = 'Carrot::Individuality::Controlled::Customized_Settings';
	while ($cursor->advance)
	{
		if ($line->is_comment_or_empty)
		{
			next;

		} elsif (my ($text) = $line->is_name)
		{
			if (defined($setting))
			{
				$setting->modify($source);
			}
			$source = IS_UNDEFINED;

			unless (exists($this->[ATR_VALUES]{$text}))
			{
				$hash_element_missing->raise_exception(
					{+HKY_DEX_BACKTRACK => $count,
					 'key' => $text},
					ERROR_CATEGORY_IMPLEMENTATION);
			}
			$setting = $this->[ATR_VALUES]{$text};

		} elsif (($text) = $line->is_source_class)
		{
#FIXME: at least consistently broken
			$text = "$anchor1$text";
			$source = $class_names->indirect_instance_from_text(
				$text);

		} elsif (($text) = $line->is_data)
		{
			next unless (length($text));
			unless (defined($source))
			{
				$source = $source_class->indirect_constructor;
			}
			$source->append_element($text);

		} elsif (($text) = $line->is_quoted_data)
		{
			unless (defined($source))
			{
				$source = $source_class->indirect_constructor;
			}
			$source->append_element($text);

		} elsif ($line->is_separator)
		{
			next;

		} else {
			die("Format of line '$line' not recognized."); #FIXME
		}
	}
	if (defined($setting))
	{
		$setting->modify($source);
	}

	return;



( run in 1.057 second using v1.01-cache-2.11-cpan-d8267643d1d )