Aion

 view release on metacpan or  search on metacpan

lib/Aion/Meta/Feature.pm  view on Meta::CPAN

	}
	
	my $accessor = $self->construct->accessor;
	eval $accessor;
	die if $@;

	if($self->{make_reader}) {
		my $reader = $self->construct->reader;
		eval $reader;
		die if $@;
	}
	
	if($self->{make_writer}) {
		my $writer = $self->construct->writer;
		eval $writer;
		die if $@;
	}
	
	if($self->{make_predicate}) {
		my $predicate = $self->construct->predicate;
		eval $predicate;
		die if $@;
	}
	
	if($self->{make_clearer}) {
		my $clearer = $self->construct->clearer;
		eval $clearer;
		die if $@;
	}
}

# Представление себя в коде
sub meta {
	my ($self) = @_;
	$self->{meta} //= do {
		my ($cls, $name) = @$self{qw/pkg name/};
		"\$Aion::META{'$cls'}{feature}{$name}"
	};
}

# Доступ к сташу со свойствами 
sub stash {
	my ($self, $key, $val) = @_;

	my $stash = $self->{stash}{scalar caller} //= {};
	
	@_ > 2? do { $stash->{$key} = $val; $self }: $stash->{$key};
}

# Сравнивает старую фичу с перезагружаемой
sub compare {
	my ($self, $other) = @_;
	
	die "Types mismatch: $other->{isa} <=> $self->{isa}" if $self->{isa} && $self->{isa} ne $other->{isa};
}

1;

__END__

=encoding utf-8

=head1 NAME

Aion::Meta::Feature - feature metadescriptor

=head1 SYNOPSIS

	use Aion::Meta::Feature;
	
	our $feature = Aion::Meta::Feature->new("My::Package", "my_feature" => (is => 'rw'));
	
	$feature->stringify  # => has my_feature => (is => 'rw') of My::Package

=head1 DESCRIPTION

Describes a feature that is added to the class by the C<has> function.

=head1 METHODS

=head2 pkg

Пакет, к которому относится фича.

	$::feature->pkg # -> "My::Package"

=head2 name

Feature name.

	$::feature->name # -> "my_feature"

=head2 opt

Feature options hash.

	$::feature->opt # --> {is => 'rw'}

=head2 has

An array of feature options in the form of key-value pairs.

	$::feature->has # --> ['is', 'rw']

=head2 construct

Feature constructor object.

	ref $::feature->construct # \> Aion::Meta::FeatureConstruct

=head2 order()

The serial number of the feature in the class.

	$::feature->order # -> 0

=head2 required (;$bool)

Flag for requiring a feature in the constructor (C<new>).

	$::feature->required(1);



( run in 1.157 second using v1.01-cache-2.11-cpan-f56aa216473 )