Aion

 view release on metacpan or  search on metacpan

lib/Aion.pm  view on Meta::CPAN

package %(cls)s {
	sub DESTROY {
		my ($self) = @_;

		warn "${\ref $self}#${\Scalar::Util::id $self} destroy in global phase!" if ${^GLOBAL_PHASE} eq 'DESTRUCT';

%(destroyers)s
	}
}
END

		my %var = (
			cls => $cls,
			destroyers => join "", @destroyers,
		);
	
		$destroyer =~ s/%\((\w+)\)s/$var{$1}/ge;

		eval $destroyer;
		die $@ if $@;
	}
	
	goto &{"${cls}::new"};
}

1;

__END__

=encoding utf-8

=head1 NAME

Aion - a postmodern object system for Perl 5, such as “Mouse”, “Moose”, “Moo”, “Mo” and “M”, but with improvements

=head1 VERSION

2.2

=head1 SYNOPSIS

	package Calc {
	
		use Aion;
	
		has a => (is => 'ro+', isa => Num);
		has b => (is => 'ro+', isa => Num);
		has op => (is => 'ro', isa => Enum[qw/+ - * \/ **/], default => '+');
	
		sub result : Isa(Me => Num) {
			my ($self) = @_;
			eval "${\ $self->a} ${\ $self->op} ${\ $self->b}";
		}
	
	}
	
	Calc->new(a => 1.1, b => 2)->result   # => 3.1

=head1 DESCRIPTION

Aion is OOP-framework for creating classes with B<features>, has B<aspects>, B<roles> and so on.

The properties declared through HAS are called B<features>.

And C<is>,C<isa>, C<default>, and so on inC<has> are called B<aspects>.

In addition to standard aspects, roles can add their own aspects using the B<aspect> subprogram.

The signature of the methods can be checked using the attribute C<:Isa(...)>.

=head1 SUBROUTINES IN CLASSES AND ROLES

C<Use Aion> imports types from the moduleC<Aion::Types> and the following subprograms:

=head2 has ($name, %aspects)

Creates a method for obtaining/setting the function (properties) of the class.

lib/Animal.pm file:

	package Animal;
	use Aion;
	
	has type => (is => 'ro+', isa => Str);
	has name => (is => 'rw-', isa => Str, default => 'murka');
	
	1;



	use lib "lib";
	use Animal;
	
	my $cat = Animal->new(type => 'cat');
	
	$cat->type   # => cat
	$cat->name   # => murka
	
	$cat->name("murzik");
	$cat->name   # => murzik

=head2 with

Adds to the module of the role. For each role, the C<import_with> method is called.

File lib/Role/Keys/Stringify.pm:

	package Role::Keys::Stringify;
	
	use Aion -role;
	
	sub keysify {
		my ($self) = @_;
		join ", ", sort keys %$self;
	}
	
	1;

File lib/Role/Values/Stringify.pm:

	package Role::Values::Stringify;

lib/Aion.pm  view on Meta::CPAN

	my @items = $anim->is_cat("cat") # @-> Returns of method `is_cat` must have the type Tuple[Bool].

The Isa attribute allows you to declare the required functions:

	package Anim { use Aion -role;
	
		sub is_cat : Isa(Me => Bool);
	}
	
	package Cat { use Aion; with qw/Anim/;
	
		sub is_cat : Isa(Me => Bool) { 1 }
	}
	
	package Dog { use Aion; with qw/Anim/;
	
		sub is_cat : Isa(Me => Bool) { 0 }
	}
	
	package Mouse { use Aion; with qw/Anim/;
		
		sub is_cat : Isa(Me => Int) { 0 }
	}
	
	Cat->new->is_cat # -> 1
	Dog->new->is_cat # -> 0
	Mouse->new # @-> Signature mismatch: is_cat(Me => Bool) of Anim <=> is_cat(Me => Int) of Mouse

=head1 SEE ALSO

Aion Ecosystem:

=over

=item * L<Aion::Annotation>

=item * L<Aion::Carp>

=item * L<Aion::Enum>

=item * L<Aion::Format>

=item * L<Aion::Fs>

=item * L<Aion::Query>

=item * L<Aion::Run>

=item * L<Aion::Spirit>

=item * L<Aion::Surf>

=item * L<Aion::Telemetry>

=item * LLL<https://metacpan.org/release/DART/config-1.4.5/view/lib/config.pm>

=item * L<Liveman>

=back

Similar OOP frameworks:

=over

=item * L<Mouse>

=item * L<Moose>

=item * L<Moo>

=item * L<Mo>

=item * L<M>

=item * L<Class::Accessor>

=item * L<Acme::Has::Tiny>

=back

Non-Moose-like:

=over

=item * L<Object::Pad>

=back

=head1 AUTHOR

Yaroslav O. Kosmina L<mailto:dart@cpan.org>

=head1 LICENSE

âš– B<GPLv3>

=head1 COPYRIGHT

The Aion module is copyright © 2023 Yaroslav O. Kosmina. Rusland. All Rights Reserved.



( run in 1.642 second using v1.01-cache-2.11-cpan-e1769b4cff6 )