| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | package Algorithm::Genetic::Diploid::Factory; | 
| 2 | 2 |  |  | 2 |  | 11 | use strict; | 
|  | 2 |  |  |  |  | 4 |  | 
|  | 2 |  |  |  |  | 710 |  | 
| 3 |  |  |  |  |  |  |  | 
| 4 |  |  |  |  |  |  | our $AUTOLOAD; | 
| 5 |  |  |  |  |  |  |  | 
| 6 |  |  |  |  |  |  | my %defaults = ( | 
| 7 |  |  |  |  |  |  | 'experiment' => 'Algorithm::Genetic::Diploid::Experiment', | 
| 8 |  |  |  |  |  |  | 'population' => 'Algorithm::Genetic::Diploid::Population', | 
| 9 |  |  |  |  |  |  | 'individual' => 'Algorithm::Genetic::Diploid::Individual', | 
| 10 |  |  |  |  |  |  | 'chromosome' => 'Algorithm::Genetic::Diploid::Chromosome', | 
| 11 |  |  |  |  |  |  | 'gene'       => 'Algorithm::Genetic::Diploid::Gene', | 
| 12 |  |  |  |  |  |  | ); | 
| 13 |  |  |  |  |  |  |  | 
| 14 |  |  |  |  |  |  | =head1 NAME | 
| 15 |  |  |  |  |  |  |  | 
| 16 |  |  |  |  |  |  | Algorithm::Genetic::Diploid::Factory - creator of objects | 
| 17 |  |  |  |  |  |  |  | 
| 18 |  |  |  |  |  |  | =head1 METHODS | 
| 19 |  |  |  |  |  |  |  | 
| 20 |  |  |  |  |  |  | =over | 
| 21 |  |  |  |  |  |  |  | 
| 22 |  |  |  |  |  |  | =item new | 
| 23 |  |  |  |  |  |  |  | 
| 24 |  |  |  |  |  |  | Constructor takes named arguments. Key is a short name (e.g. 'gene'), value is a fully | 
| 25 |  |  |  |  |  |  | qualified package name from which to instantiate objects identified by the short name. | 
| 26 |  |  |  |  |  |  |  | 
| 27 |  |  |  |  |  |  | =cut | 
| 28 |  |  |  |  |  |  |  | 
| 29 |  |  |  |  |  |  | sub new { | 
| 30 | 2 |  |  | 2 | 1 | 2152 | my $class = shift; | 
| 31 | 2 |  |  |  |  | 16 | my %self = ( %defaults, @_ ); | 
| 32 | 2 |  |  |  |  | 6 | for my $class ( values %self ) { | 
| 33 | 10 | 100 |  |  |  | 33 | if ( not $::{ $class . '::' } ) { | 
| 34 | 8 |  |  |  |  | 426 | eval "require $class"; | 
| 35 | 8 | 50 |  |  |  | 32 | if ( $@ ) { | 
| 36 | 0 |  |  |  |  | 0 | die $@; | 
| 37 |  |  |  |  |  |  | } | 
| 38 |  |  |  |  |  |  | } | 
| 39 |  |  |  |  |  |  | } | 
| 40 | 2 |  |  |  |  | 26 | return bless \%self, $class; | 
| 41 |  |  |  |  |  |  | } | 
| 42 |  |  |  |  |  |  |  | 
| 43 |  |  |  |  |  |  | =item create | 
| 44 |  |  |  |  |  |  |  | 
| 45 |  |  |  |  |  |  | Given a short hand name, instantiates an object whose package name is associated with | 
| 46 |  |  |  |  |  |  | that short name. | 
| 47 |  |  |  |  |  |  |  | 
| 48 |  |  |  |  |  |  | =cut | 
| 49 |  |  |  |  |  |  |  | 
| 50 |  |  |  |  |  |  | sub create { | 
| 51 | 251 |  |  | 251 | 1 | 620 | my ( $self, $thing, @args ) = @_; | 
| 52 | 251 |  |  |  |  | 13100 | return $self->{$thing}->new(@args); | 
| 53 |  |  |  |  |  |  | } | 
| 54 |  |  |  |  |  |  |  | 
| 55 |  |  |  |  |  |  | =item create_experiment | 
| 56 |  |  |  |  |  |  |  | 
| 57 |  |  |  |  |  |  | Instantiates a L object, or subclass thereof. | 
| 58 |  |  |  |  |  |  |  | 
| 59 |  |  |  |  |  |  | =item create_population | 
| 60 |  |  |  |  |  |  |  | 
| 61 |  |  |  |  |  |  | Instantiates a L object, or subclass thereof. | 
| 62 |  |  |  |  |  |  |  | 
| 63 |  |  |  |  |  |  | =item create_individual | 
| 64 |  |  |  |  |  |  |  | 
| 65 |  |  |  |  |  |  | Instantiates a L object, or subclass thereof. | 
| 66 |  |  |  |  |  |  |  | 
| 67 |  |  |  |  |  |  | =item create_chromosome | 
| 68 |  |  |  |  |  |  |  | 
| 69 |  |  |  |  |  |  | Instantiates a L object, or subclass thereof. | 
| 70 |  |  |  |  |  |  |  | 
| 71 |  |  |  |  |  |  | =item create_gene | 
| 72 |  |  |  |  |  |  |  | 
| 73 |  |  |  |  |  |  | Instantiates a L object, or subclass thereof. | 
| 74 |  |  |  |  |  |  |  | 
| 75 |  |  |  |  |  |  | =back | 
| 76 |  |  |  |  |  |  |  | 
| 77 |  |  |  |  |  |  | =cut | 
| 78 |  |  |  |  |  |  |  | 
| 79 |  |  |  |  |  |  | sub AUTOLOAD { | 
| 80 | 251 |  |  | 251 |  | 332 | my $self = shift; | 
| 81 | 251 |  |  |  |  | 294 | my $method = $AUTOLOAD; | 
| 82 | 251 |  |  |  |  | 918 | $method =~ s/.+://; | 
| 83 | 251 | 50 |  |  |  | 994 | if ( $method =~ /^create_(.+)$/ ) { | 
| 84 | 251 |  |  |  |  | 470 | my $thing = $1; | 
| 85 | 251 |  |  |  |  | 554 | $self->create( $thing, @_ ); | 
| 86 |  |  |  |  |  |  | } | 
| 87 |  |  |  |  |  |  | } | 
| 88 |  |  |  |  |  |  |  | 
| 89 |  |  |  |  |  |  | 1; |