NAME
MOP4Import::Types - create multiple inner-classes at once.
SYNOPSIS
Create inner-classes MyApp::Artist
and MyApp::CD
using MOP4Import::Types.
package MyApp;
use MOP4Import::Types
(Artist => [[fields => qw/artistid name/]]
, CD => [[fields => qw/cdid artistid title year/]]);
Then you can use above types like following with static checking of fields.
sub print_artist_cds {
(my $self, my Artist $artist) = @_;
my @cds = $self->DB->select(CD => {artistid => $artist->{artistid}});
foreach my CD $cd (@cds) {
print tsv($cd->{title}, $cd->{year}), "\n";
}
}
DESCRIPTION
MOP4Import::Types is yet another protocol implementation of MOP4Import family.
In contrast to MOP4Import::Declare, which is designed to modify target module itself, this module is designed to add new inner-classes to target module.
With "inner-class", I mean class declared in some module and not directly exposed as "require" able module.
"MetaObject Protocol for Import" in this module
import()
method of MOP4Import::Types briefly does following:
sub import {
my ($myPack, @pairs) = @_;
my $callpack = caller;
my $opts = +{};
while (my ($typename, $pragma_list) = splice @pairs, 0, 2) {
my $innerClass = join("::", $callpack, $typename);
$myPack->declare___type($opts, $callpack, $typename, $innerClass);
}
}