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.
# 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.
# 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;
# 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;