Different Initializers for Different Numbers of Arguments

Under the hood, List::Compare::new() calls a different _init() routine depending on the number of arguments passed to it:

    sub new {
        $class = shift;
        @args = @_;
        if (@args > 2) {
            $class .= '::Multiple';
            $self = bless {}, ref($class) || $class;
        } else {
            $self = bless {}, ref($class) || $class;
        }
        $dataref = $self->_init(@args);
        %$self = %$dataref;
        return $self;
    }

Previous Back to start of show Next
Slide: 47 args_for_initializers © 2003 James E. Keenan