Skip to content

Commit

Permalink
simplify clone interface to use Storable::dclone() which is both matu…
Browse files Browse the repository at this point in the history
…re and available with core
  • Loading branch information
jmmills authored and jhannah committed Sep 28, 2010
1 parent ec6035b commit af3b2a1
Showing 1 changed file with 5 additions and 43 deletions.
48 changes: 5 additions & 43 deletions lib/Text/FixedWidth.pm
Expand Up @@ -4,27 +4,7 @@ use warnings;
use strict;
use Carp;
use vars ('$AUTOLOAD');

our $_CLONE_METHODS = [
{
package => 'Clone::Fast',
call => sub {
Clone::Fast::clone(shift);
}
},
{
package => 'Clone::More',
call => sub {
Clone::More::clone(shift);
}
},
{
package => 'Storable',
call => sub {
Storable::dclone(shift);
}
}
];
use Storable ();

=head1 NAME
Expand Down Expand Up @@ -135,7 +115,7 @@ sub parse {

die ref($self).":Please provide a string argument" if (!$args{string});
my $string = $args{string};

$self = $self->clone if $args{clone};

my $offset = 0;
Expand Down Expand Up @@ -182,7 +162,7 @@ sub string {
my $tmp;
if (
$sprintf =~ /\%\d*[duoxefgXEGbB]/ && ( # perldoc -f sprintf
(not defined $value) ||
(not defined $value) ||
$value eq "" ||
$value !~ /^(\d+\.?\d*|\.\d+)$/ # match valid number
)
Expand Down Expand Up @@ -248,25 +228,7 @@ See L</parse> for further information.

sub clone {
my $self = shift;

unless ( ref( $self->{_clone_method} ) eq 'CODE' ) {
foreach( @{ $_CLONE_METHODS } ) {
my $package = $_->{package};
my $call = $_->{call};

eval qq{
require $package;
$package->import();
};

unless( $@ ) {
$self->{_clone_method} = $call;
last;
}
}
}

return $self->{_clone_method}->($self);
return Storable::dclone($self);
}


Expand Down Expand Up @@ -325,7 +287,7 @@ sub AUTOLOAD {

=head1 ALTERNATIVES
Other modules that may do similar things:
Other modules that may do similar things:
L<Parse::FixedLength>,
L<Text::FixedLength>,
L<Data::FixedFormat>,
Expand Down

0 comments on commit af3b2a1

Please sign in to comment.