CONFIG

 view release on metacpan or  search on metacpan

Plain.pm  view on Meta::CPAN

	my ($self) = @_;
	return $self->{COMMON}->{FILEBYTES};
}

sub file_lines($) {
	my ($self) = @_;
	return $self->{COMMON}->{FILELINES};
}

sub cache_size($) {
	my ($self) = @_;
	return $self->{COMMON}->{CACHEBYTES};
}

sub cache_lines($) {
	my ($self) = @_;
	return $self->{COMMON}->{CACHELINES};
}
sub file_read($) {
	my ($self) = @_;
	return $self->{COMMON}->{USED};
}

sub file_config($) {
	my ($self) = @_;
	my %hash;
	
	%hash = %{$self->{COMMON}->{CONFIG}};	

	# remove internal stuff
	delete $hash{COMMENT_FUNCTIONS};
	return \%hash;
}


sub DESTROY {
	my ($self) = @_;

	$self->{COMMON}->{ACTIVE}--;
}

#####################################################################
# read_file
#
# check if file has to be (re)read
#
# parameters: 1st -> object ref
sub read_file ($) {
	my ($self) = @_;
	my @f_stat;

	$self->{COMMON}->{LASTCHECKED} = time;	
	$self->{COMMON}->{GLOBALERROR} = ();

	if (! defined $self->{COMMON}->{LASTREAD}) {
		return $self->force_read_file;
	}

	if (! defined $self->{COMMON}->{CONFIG}->{DATA}) {
		# no reread required if DATA option was used
		@f_stat = stat($self->{COMMON}->{FILENAME});
	
		if ($f_stat[9] > $self->{COMMON}->{LASTREAD}) {
			$self->{COMMON}->{LASTCHANGED} = 
						scalar(localtime($f_stat[9]));
			return $self->force_read_file;	
		}
	}
}

#####################################################################
# force_read_file
#
# try to open file, (create error if neccessary) and set timestamp
sub force_read_file {
	my ($self) = @_;
	my $fh = new FileHandle;
	my @f_stat;

	if (defined $self->{COMMON}->{CONFIG}->{DATA}) {
		$self->{COMMON}->{LASTREAD} = time;
		$self->{COMMON}->{FILETIME} = time;
		$self->read_file_into_cache();
	} elsif ($fh->open($self->{COMMON}->{FILENAME})) {
		$self->{COMMON}->{LASTREAD} = time;
		@f_stat = stat($fh);
		$self->{COMMON}->{FILETIME} = $f_stat[9];
		$self->read_file_into_cache($fh);	
	} else {
		push(@{$self->{COMMON}->{GLOBALERROR}}, $!);
	} 
}

#####################################################################
# read_file_into_cache
#
# reads the file linewhise into the memory and applyies the
# configuration options (remove comments and so on...)
#
# parameters: 1st -> object
#             2nd -> filehandle
sub read_file_into_cache {
	my ($self, $fh) = @_;
	my $linenr = undef;	# first input_linenr of multi line
	my $input_linenr = 0;
	my $line;
	my $long_line = "";
	my $cache_bytes = 0;
	my $file_bytes  = 0;

	$self->{COMMON}->{REPARSE}     = '1';
	$self->{COMMON}->{PLAINFILE}   = "";	
	$self->{COMMON}->{LINESFILE}   = ();
	$self->{COMMON}->{LINESFILE_unparsed} = ();
	$self->{COMMON}->{INPUTLINE}   = ();
	$self->{COMMON}->{FILELINE}    = ();
	$self->{COMMON}->{GLOBALERROR} = ();
	$self->{COMMON}->{LINEERROR}   = ();
	
	if (defined $fh) {
		$line = $fh->getline;
	} else {
		if ($self->{COMMON}->{CONFIG}->{DATA} !~ m/\n$/s) {
			$self->{COMMON}->{CONFIG}->{DATA} .= "\n";
		}

		$self->{COMMON}->{CONFIG}->{DATA} =~ s/^(.*?\n)(.*)$/$2/s; 
		$line = $1;
	}

	while (defined $line) {
		$input_linenr ++;
		$self->{COMMON}->{LINESFILE_unparsed}->[$input_linenr] = $line;
		$file_bytes += length($line);
		$long_line .= $line;
		if ($self->apply_config(\$long_line)) {
			# line contains "\n", so store in cache
			if (! defined $linenr) {
				$linenr = $input_linenr;
			}
			$self->check_for_include($long_line, $linenr);

			undef $linenr;
			$long_line = "";
		} else {
			# line contains no "\n", so merge with next line



( run in 1.673 second using v1.01-cache-2.11-cpan-75ffa21a3d4 )