| 1 | package AutoCode::MarshalRoot; | ||
| 2 | use strict; | ||
| 3 | use AutoCode::Root; | ||
| 4 | our @ISA=qw(AuotCode::Root); | ||
| 5 | |||
| 6 | sub import { | ||
| 7 | my ($class, $selector)=@_; | ||
| 8 | my $caller = caller; | ||
| 9 | no strict 'refs'; | ||
| 10 | push @{"$caller\::ISA"}, __PACKAGE__ ; | ||
| 11 | ${"$caller\::marshal_module"}=$caller; | ||
| 12 | } | ||
| 13 | |||
| 14 | sub new { | ||
| 15 | my ($caller, @args)=@_; | ||
| 16 | my $class=ref($caller)||$caller; | ||
| 17 | no strict 'refs'; | ||
| 18 | my $marshal=${"$class\::marshal_module"}; | ||
| 19 | my $selector=${"$call\::selector"}; | ||
| 20 | use strict 'refs'; | ||
| 21 | if($class =~ /$marshal::(\S+)/){ | ||
| 22 | my $self=$class->SUPER::new(@args); | ||
| 23 | $self->_initialize(@args); | ||
| 24 | return $self; | ||
| 25 | }else{ | ||
| 26 | my %params = @args; | ||
| 27 | @params{map{lc $_}keys $params}=values %params; | ||
| 28 | my $private = $params{$selector}||$params{"-$selector"}; | ||
| 29 | $private ||= $class->_guess_private(@args); | ||
| 30 | $class->throw("Unknown $selector given") unless $private; | ||
| 31 | my $private_module="$marshal\::$private"; | ||
| 32 | return undef unless($class->_load_module($private_module); | ||
| 33 | return $private_module->new(@args); | ||
| 34 | } | ||
| 35 | } | ||
| 36 | |||
| 37 | 1; | ||
| 38 | __END__ |