Object-InsideOut - Re: Passing 'straight' arguements to a constructor.

Posted on Fri Jan 6 15:42:47 2006 by jdhedden in response to 1572 (See the whole thread of 3)
Re: Passing 'straight' arguements to a constructor.
    ... for some object construction I'd prefer access to @_ as passed to new. Especially when recreating existing APIs.

The cons of passing non-parameterized arguments in an object constructor are discussed in Perl Best Practices, and Object::InsideOut was written to follow most of Damian Conway's suggestions (with the additional flexibility of not putting everything into a hash ref).

However, to workaround the requirement for parameterized arguments, you can just put a wrapper around Object::InsideOut's new() method as follows:
#!/usr/bin/perl use strict; use warnings; package My::Class; { use Object::InsideOut; my %init_args :InitArgs = ( 'args' => '' ); sub init :Init { my ($self, $args) = @_; my @args = @{$args->{'args'}}; # Here's your non-parameterized args! print ('Args: ', join(', ', @args), "\n"); } # A wrapper around Object::InsideOut's ->new() method sub new { my $thing = shift; return ($thing->Object::InsideOut::new('args' => [ @_ ])); } } package main; MAIN: { my $obj = My::Class->new(1, 3, 9); } exit(0);
Direct Responses: 1594 | Write a response