Config-IniFiles
view release on metacpan or search on metacpan
lib/Config/IniFiles.pm view on Meta::CPAN
if ( !ref($ref) )
{
return $ref;
}
if ( UNIVERSAL::isa( $ref, "ARRAY" ) )
{
return [ map { _deepcopy($_) } @$ref ];
}
if ( UNIVERSAL::isa( $ref, "HASH" ) )
{
my $return = {};
foreach my $k ( keys %$ref )
{
$return->{$k} = _deepcopy( $ref->{$k} );
}
return $return;
}
carp "Unhandled data structure in $ref, cannot _deepcopy()";
}
# Internal method, gets the next line, taking proper care of line endings.
sub _nextline
{
my ( $self, $fh ) = @_;
my $s = '';
if ( !exists $self->{line_ends} )
{
# no $self->{line_ends} is a hint set by caller that we are at
# the first line (kludge kludge).
{
local $/ = \1;
my $nextchar;
do
{
$nextchar = <$fh>;
return undef if ( !defined $nextchar );
$s .= $nextchar;
} until ( $s =~ m/((\015|\012|\025|\n)$)/s );
$self->{line_ends} = $1;
if ( $nextchar eq "\x0d" )
{
# peek at the next char
$nextchar = <$fh>;
if ( $nextchar eq "\x0a" )
{
$self->{line_ends} .= "\x0a";
}
else
{
seek $fh, -1, SEEK_CUR();
}
}
}
# If there's a UTF BOM (Byte-Order-Mark) in the first
# character of the first line then remove it before processing
# ( http://www.unicode.org/unicode/faq/utf_bom.html#22 )
$s =~ s/\A//;
return $s;
}
else
{
local $/ = $self->{line_ends};
return scalar <$fh>;
}
}
# Internal method, closes or resets the file handle. To be called
# whenever ReadConfig() returns.
sub _rollback
{
my ( $self, $fh ) = @_;
# Only close if this is a filename, if it's
# an open handle, then just roll back to the start
if ( !ref( $self->{cf} ) )
{
close($fh) or Carp::confess("close failed: $!");
}
else
{
# Attempt to rollback to beginning, no problem if this fails (e.g. STDIN)
seek( $fh, 0, SEEK_SET() );
} # end if
}
sub _no_filename
{
my $self = shift;
my $fn = $self->{cf};
return ( not( defined($fn) && length($fn) ) );
}
sub _read_line_num
{
my $self = shift;
if (@_)
{
$self->{_read_line_num} = shift;
}
return $self->{_read_line_num};
}
# Reads the next line and removes the end of line from it.
sub _read_next_line
{
my ( $self, $fh ) = @_;
my $line = $self->_nextline($fh);
if ( !defined($line) )
{
( run in 1.724 second using v1.01-cache-2.11-cpan-5b529ec07f3 )