From: rkinyon Date: Thu, 23 Feb 2006 00:28:19 +0000 (+0000) Subject: Converted to use _get_args() to make all new/tie argument handling the same X-Git-Tag: 0-97~21 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=0ca7ea98550b6f782b4b68be8b261218ff097f74;p=dbsrgits%2FDBM-Deep.git Converted to use _get_args() to make all new/tie argument handling the same --- diff --git a/lib/DBM/Deep.pm b/lib/DBM/Deep.pm index 04e5835..bb73250 100644 --- a/lib/DBM/Deep.pm +++ b/lib/DBM/Deep.pm @@ -104,6 +104,29 @@ sub TYPE_HASH () { return SIG_HASH; } sub TYPE_ARRAY () { return SIG_ARRAY; } sub TYPE_SCALAR () { return SIG_SCALAR; } +sub _get_args { + my $proto = shift; + + my $args; + if (scalar(@_) > 1) { + if ( @_ % 2 ) { + $proto->_throw_error( "Odd number of parameters to " . (caller(1))[2] ); + } + $args = {@_}; + } + elsif ( my $type = Scalar::Util::reftype($_[0]) ) { + if ( $type ne 'HASH' ) { + $proto->_throw_error( "Not a hashref in args to " . (caller(1))[2] ); + } + $args = $_[0]; + } + else { + $args = { file => shift }; + } + + return $args; +} + sub new { ## # Class constructor method for Perl OO interface. @@ -111,9 +134,7 @@ sub new { # providing a hybrid OO/tie interface. ## my $class = shift; - my $args; - if (scalar(@_) > 1) { $args = {@_}; } - else { $args = { file => shift }; } + my $args = $class->_get_args( @_ ); ## # Check if we want a tied hash or array. diff --git a/lib/DBM/Deep/Array.pm b/lib/DBM/Deep/Array.pm index 8fd633a..6c7d7d4 100644 --- a/lib/DBM/Deep/Array.pm +++ b/lib/DBM/Deep/Array.pm @@ -17,22 +17,7 @@ sub TIEARRAY { # Tied array constructor method, called by Perl's tie() function. ## my $class = shift; - my $args; - if (scalar(@_) > 1) { - if ( @_ % 2 ) { - $class->_throw_error( "Odd number of parameters to TIEARRAY" ); - } - $args = {@_}; - } - elsif ( my $type = Scalar::Util::reftype($_[0]) ) { - if ( $type ne 'HASH' ) { - $class->_throw_error( "Not a hashref in TIEARRAY" ); - } - $args = $_[0]; - } - else { - $args = { file => shift }; - } + my $args = $class->_get_args( @_ ); $args->{type} = $class->TYPE_ARRAY; diff --git a/lib/DBM/Deep/Hash.pm b/lib/DBM/Deep/Hash.pm index 98b5d7e..1f95438 100644 --- a/lib/DBM/Deep/Hash.pm +++ b/lib/DBM/Deep/Hash.pm @@ -13,20 +13,7 @@ sub TIEHASH { # Tied hash constructor method, called by Perl's tie() function. ## my $class = shift; - my $args; - if (scalar(@_) > 1) { - if ( @_ % 2 ) { - $class->_throw_error( "Odd number of parameters to TIEHASH" ); - } - $args = {@_}; - } - elsif ( my $type = Scalar::Util::reftype($_[0]) ) { - if ( $type ne 'HASH' ) { - $class->_throw_error( "Not a hashref in TIEHASH" ); - } - $args = $_[0]; - } - else { $args = { file => shift }; } + my $args = $class->_get_args( @_ ); $args->{type} = $class->TYPE_HASH;