-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 =pod Here's some code that seems to turn up more and more frequently: lang:Perl package Useful::Function; use Moose; has 'args' => ( is => 'ro', isa => 'ArrayRef[Str]', required => 1, auto_deref => 1, ); sub function { my $self = shift; my @args = $self->args; return ...; } Then it's used like this: my $useful_function = Useful::Function->new( args => [1,2,3] ); my $result = $useful_function->function(); ... I think people do this because they like type constraints and coercions, but it sure seems like an abuse of the class system. Clearly we could rewrite the above class as a small function: sub function { my @args = @_; return ...; } function(1,2,3); Or, if we want to reuse the same arguments repeatedly: sub make_function { my %params = @_; return sub { my @args = @{ $params{args} || [] }; return ...; } } my $func = make_function( args => [1,2,3] ); $func->(); $func->(); For validating the arguments, you can use C or C. (And if you are writing a function-based module, you should also look at C. It provides a lot of sugar, and can even automate the "currying" in the second example for you.) It's not just Perl programmers that do this. I was reading some Lisp code last weekend and noticed this: lang:Common Lisp (defclass arguments-for-foo () ((arg1 :accessor arg1 :initform 10 :initarg :arg1) (arg2 :accessor arg2 :initform 20 :initarg :arg2))) (defmethod foo ((args arguments-for-foo)) (+ (arg1 args) (arg2 args))) (foo (make-instance 'arguments-for-foo :arg2 42)) I found it amusingly verbose, especially with CL's built-in C<&key> lambda list keyword: (defun foo (&key (arg1 10) (arg2 20)) (+ arg1 arg2)) (foo :arg2 42) Anyway, the next time you are writing a class, ask yourself "Isn't this just a function!?" If the answer is "yes", then just write a function! Unless, of course, you are using Java. -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.9 (GNU/Linux) iEYEARECAAYFAkjWEU8ACgkQ2rw+dVvzZm0h1ACghnfNrdHZAM199lINbam9/dRs ALcAnA0/fmmnkuqgQbij5+SsGhI5wFT8 =F+br -----END PGP SIGNATURE-----