| 1 | package AutoCode::ObjectFactory; | ||
| 2 | use strict; | ||
| 3 | use AutoCode::ModuleFactory; | ||
| 4 | # use AutoCode::Object; | ||
| 5 | our @ISA=qw(AutoCode::ModuleFactory); | ||
| 6 | |||
| 7 | |||
| 8 | sub get_instance { | ||
| 9 | my ($self, $type, @args)=@_; | ||
| 10 | my $module = $self->schema->get_module_definition($type); | ||
| 11 | my %module =%$module; | ||
| 12 | my @subs = grep /^[_a-zA-Z]/, keys %module; | ||
| 13 | my @decls= grep /^\~/, keys %module; | ||
| 14 | my @scalar_accessors = grep /^\$/, @subs; | ||
| 15 | my @array_accessors = grep /^\@/, @subs; | ||
| 16 | |||
| 17 | my $virtual_package = $self->make_virtual_module($type); | ||
| 18 | # The package and constructor are fixed as 'AutoSQL::Object' and 'new' | ||
| 19 | my $instance; | ||
| 20 | |||
| 21 | $instance = $virtual_package->new(@args); | ||
| 22 | =item | ||
| 23 | this is wrongdoing, since the scalar_accessors and array_accessors will | ||
| 24 | be placed under AutoSQL::Object typeglob | ||
| 25 | |||
| 26 | $instance = AutoSQL::Object->new( | ||
| 27 | -scalar_accessors => \@scalar_accessors, | ||
| 28 | -array_accessors => \@array_accessors, | ||
| 29 | -factory => $self, | ||
| 30 | -type => $type, | ||
| 31 | @args); | ||
| 32 | =cut | ||
| 33 | |||
| 34 | # Cache it, by $type and digest of @args. | ||
| 35 | # Implement it later. | ||
| 36 | |||
| 37 | |||
| 38 | return $instance; | ||
| 39 | } | ||
| 40 | |||
| 41 | 1; | ||
| 42 |