Class-Mix

 view release on metacpan or  search on metacpan

lib/Class/Mix.pm  view on Meta::CPAN

This provides the desired inheritance without creating superfluous
classes.  These special cases only apply if the options are compatible
with the pre-existing class.

This function relies on the classes it returns remaining unmodified in
order to be returned by future invocations.  If you want to modify your
dynamically-generated `anonymous' classes, use C<genpkg> (below).

=cut

sub genpkg(;$);

my %mixtures;
sub mix_class(@) {
	my @parents;
	my %options;
	foreach(@_) {
		if(is_string($_)) {
			push @parents, $_;
		} elsif(is_ref($_, "HASH")) {
			foreach my $k (keys %$_) {
				croak "clashing option `$k'"
					if exists $options{$k};
				$options{$k} = $_->{$k};

lib/Class/Mix.pm  view on Meta::CPAN

It must be either the empty string (to create a top-level package)
or a bareword followed by "::" (to create a package under that name).
For example, "Digest::" could be specified to ensure that the resulting
package has a name starting with "Digest::", so that C<< Digest->new >>
will accept it as the name of a message digest algorithm.  If the PREFIX
is not supplied, the caller is not expressing any preference.

=cut

my $n = 0;
sub genpkg(;$) {
	my($prefix) = @_;
	$prefix = "Class::Mix::" unless defined $prefix;
	croak "`$prefix' is not a valid module name prefix"
		unless $prefix =~ /\A$prefix_rx\z/o;
	no strict "refs";
	my $pkgtail;
	do {
		$pkgtail = "__GP".$n++;
	} while(exists ${$prefix || "::"}{$pkgtail."::"});
	my $pkgname = $prefix.$pkgtail;



( run in 0.730 second using v1.01-cache-2.11-cpan-65fba6d93b7 )