From: Don Armstrong Date: Tue, 17 Feb 2004 03:08:13 +0000 (+0000) Subject: * Moving around code to bring it into order with the documentation X-Git-Url: https://git.donarmstrong.com/?p=class_modular.git%2F.git;a=commitdiff_plain;h=e32b1487d61b9d534d10a856b60c9de6b4410fca * Moving around code to bring it into order with the documentation git-svn-id: file:///srv/don_svn/class_modular/trunk@16 96c6a18b-02ce-0310-9fca-9eb62c757ba6 --- diff --git a/lib/Class/Modular.pm b/lib/Class/Modular.pm index 5611de9..8fef35c 100644 --- a/lib/Class/Modular.pm +++ b/lib/Class/Modular.pm @@ -50,57 +50,6 @@ BEGIN{ our $AUTOLOAD; -=head2 new - -=head3 Usage - - $obj = Foo::Bar->new(); - -=head3 Function - -Creates a new C object. - -Aditional arguments can be passed to this creator, and they are stored -in C<$self->{_creation_args}>. You can also override the new method in -your subclass. It's just provided here for completeness. - -=cut - -sub new { - my ($class,@args) = @_; - - # We shouldn't be called $me->new, but just in case - $class = ref($class) || $class; - - my $self = {}; - bless $self, $class; - - $self->_init(@args); - - return $self; -} - - -=head2 _init - -=head3 Usage - - $self->_init(@args); - -=head3 Function - -Stores the arguments used at new so modules that are loaded later can -read them - -=cut - -sub _init { - my ($self,@creation_args) = @_; - - $self->{creation_args} = [@_]; -} - - =head2 load =head3 Usage @@ -146,46 +95,6 @@ sub load($$;$) { } } -=head2 _addmethods - -=head3 Usage - - $self->_addmethods($subclass,&{"${subclass}::_methods"}($self,$options)); - -=head3 Function - -Given an array of methods, adds the methods into the _methodhash -calling table. - -Methods that have previously been overridden by override are _NOT_ -overridden again. This may need to be adjusted in load. - -=cut - -sub _addmethods($@) { - my ($self,$subclass,@methods) = @_; - - # stick the method into the table - # DLA: Make with the munchies! - - foreach my $method (@methods) { - if (not $method =~ /^$subclass/) { - $method = $subclass.'::'.$method; - } - my ($method_name) = $method =~ /\:*([^\:]+)\s*$/; - if (exists $self->{_methodhash}->{$method_name}) { - if ($self->{_methodhash}->{$method_name}->{overridden}) { - carp "Not overriding already overriden method $method_name\n" if $DEBUG; - next; - } - carp "Overriding $method_name $self->{_methodhash}->{$method_name}->{reference} with $method\n"; - } - $self->{_methodhash}->{$method_name}->{reference} = $method; - $self->{_methodhash}->{$method_name}->{subclass} = $subclass; - } - -} - =head2 override =head3 Usage @@ -331,6 +240,68 @@ sub handledby{ return undef; } +=head1 INTERNAL FUNCTIONS + +The functions below are functions internal to Class::Modular. The +first two, new and _init should probably be overriden in any class +that inherits from Class::Modular, but they are provided just in case +you don't want to write a new and/or _init. + +=cut + +=head2 new + +=head3 Usage + + $obj = Foo::Bar->new(); + +=head3 Function + +Creates a new C object. + +Aditional arguments can be passed to this creator, and they are stored +in C<$self->{_creation_args}>. You can also override the new method in +your subclass. It's just provided here for completeness. + +=cut + +sub new { + my ($class,@args) = @_; + + # We shouldn't be called $me->new, but just in case + $class = ref($class) || $class; + + my $self = {}; + bless $self, $class; + + $self->_init(@args); + + return $self; +} + + +=head2 _init + +=head3 Usage + + $self->_init(@args); + +=head3 Function + +Stores the arguments used at new so modules that are loaded later can +read them + +This function is called by default from new. Classes may only wish to +override _init. + +=cut + +sub _init { + my ($self,@creation_args) = @_; + + $self->{creation_args} = [@_]; +} + =head2 DESTROY @@ -348,6 +319,48 @@ disconnected or closed. =cut +=head2 _addmethods + +=head3 Usage + + $self->_addmethods($subclass,&{"${subclass}::_methods"}($self,$options)); + +=head3 Function + +Given an array of methods, adds the methods into the _methodhash +calling table. + +Methods that have previously been overridden by override are _NOT_ +overridden again. This may need to be adjusted in load. + +=cut + +sub _addmethods($@) { + my ($self,$subclass,@methods) = @_; + + # stick the method into the table + # DLA: Make with the munchies! + + foreach my $method (@methods) { + if (not $method =~ /^$subclass/) { + $method = $subclass.'::'.$method; + } + my ($method_name) = $method =~ /\:*([^\:]+)\s*$/; + if (exists $self->{_methodhash}->{$method_name}) { + if ($self->{_methodhash}->{$method_name}->{overridden}) { + carp "Not overriding already overriden method $method_name\n" if $DEBUG; + next; + } + carp "Overriding $method_name $self->{_methodhash}->{$method_name}->{reference} with $method\n"; + } + $self->{_methodhash}->{$method_name}->{reference} = $method; + $self->{_methodhash}->{$method_name}->{subclass} = $subclass; + } + +} + + + sub DESTROY{ my $self = shift; foreach my $subclass (keys %{$self->{_subclasses}}) {