Class::Clone

Class::Clone is a Perl module to create a subclass or a copy of a class on-the-fly.
Download

Class::Clone Ranking & Summary

Advertisement

  • Rating:
  • License:
  • Perl Artistic License
  • Price:
  • FREE
  • Publisher Name:
  • Tyler MacDonald
  • Publisher web site:
  • http://search.cpan.org/~crakrjack/

Class::Clone Tags


Class::Clone Description

Class::Clone is a Perl module to create a subclass or a copy of a class on-the-fly. Class::Clone is a Perl module to create a subclass or a copy of a class on-the-fly.SYNOPSIS # Another::Package gets its methods from Some::Package, # but to SUPER:: in Another::Pacakge will go to Another::Package::Super, package Some::Package::Super; sub method { my $class = shift; return "method"; } package Some::Package; sub method { my $class = shift; return $class->SUPER::method . "ical"; } package Another::Package::Super; sub method { return "naut"; } package main; use Class::Clone qw(class_clone); use Test::More qw(no_plan); @Some::Package::ISA = qw(Some::Package::Super); class_clone('Some::Package', 'Another::Package'); @Another::Package::ISA = qw(Another::Package::Super); is( Another::Package->method, 'nautical', "Another::Package's namespace is completely independant of Some::Package" );Class::Clone makes an exact clone of an existing class, whose variables and subroutines are not in any way tied back to the existing class or it's parent classes. If you change any variables in the clone, the changes don't affect the parent class. When a cloned subroutine has a call like $self->SUPER::do_something()the clone class's parents are traversed. This module is called Class::Clone because this behaviour lends itself well to creating certain types of factory / polymorph classes.(This is in contrast to importing variable or subroutine references from other packages, typically via 'Exporter'. When you do that, your copy is the original copy, so changing inherited variables affects your parent packages, and SUPER:: will call the original parent's parent, even if you change your @ISA) Requirements: · Perl


Class::Clone Related Software