SPUG: Class::Multimethod Question

Damian Conway damian at cs.monash.edu.au
Fri Jul 7 21:35:42 CDT 2000


 
   > A current possible workaround is:

	[tidy solution deleted]
   
  
   > However, it would be nice to have Multimethods actually do the right 
   > thing for new without requiring this workaround.

I'm currently contemplating extending the parameter specification model
so that one could specify a pattern that scalar value arguments should
match:

	package Foo;
	use Class::Multimethods;

	multimethod new => (qr/Foo/) => sub {
		bless {}, $_[0];
	}

	multimethod new => (qr/Foo/, HASH) => sub {
		bless { %$_[1] }, $_[0];
	}

	multimethod new => (qr/Foo/, ARRAY) => sub {
		my %data;
		@data{qw(name rank serialnum)} = @$_[1];
		bless \%data, $_[0];
	}

This would solve the problem, but the syntax is ugly :-(

Damian

 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
     POST TO: spug-list at pm.org       PROBLEMS: owner-spug-list at pm.org
 Seattle Perl Users Group (SPUG) Home Page: http://www.halcyon.com/spug/
     Subscriptions; Email to majordomo at pm.org:  ACTION  LIST  EMAIL
  Replace ACTION by subscribe or unsubscribe, EMAIL by your Email-address
 For full traffic, use spug-list for LIST ; otherwise use spug-list-digest





More information about the spug-list mailing list