Clarion

 view release on metacpan or  search on metacpan

lib/Clarion.pm  view on Meta::CPAN

package Clarion;

use 5.006;
use strict;
use warnings;

use FileHandle;

our $VERSION = '1.02';

=head1 NAME

Clarion - Perl module for reading CLARION 2.1 data files

=head1 DESCRIPTION

This is a perl module to access CLARION 2.1 files.
At the moment only read access to the files is implemented.
"Encrypted" (owned) files are processed transparently,
there is no need to specify the password of a file.

=head1 SYNOPSIS

	use Clarion;

	my $dbh=new Clarion "customer.dat";

	print $dbh->file_struct;

	for ( 1 .. $dbh->last_record ) {
    		my $r=$dbh->get_record_hash($_);
		next if $r->{_DELETED};
	    	print $r->{CODE}." ".$r->{NAME}." ".$r->{PHONE}."\n";
	}

	$dbh->close();

=head1 METHODS

=over 4

=cut

sub FILLOCK { 0x01; }	# file is locked
sub FILOWN  { 0x02; }	# file is owned
sub FILCRYP { 0x04; }	# records are encrypted
sub FILMEMO { 0x08; }	# memo file exists
sub FILCOMP { 0x10; }	# file is compressed
sub FILRCLM { 0x20; }	# reclaim deleted records
sub FILREAD { 0x40; }	# file is read only
sub FILCRET { 0x80; }	# file may be created

sub RECNEW  { 0x01; }	# bit 0 - new record
sub RECOLD  { 0x02; }	# bit 1 - old record
sub RECREV  { 0x04; }	# bit 2 - revised record
sub RECDEL  { 0x10; }	# bit 4 - deleted record
sub RECHLD  { 0x40; }	# bit 6 - record held

=item $h=new Clarion ["file.dat" [, 1]]

Create object for reading Clarion file. If file name is specified then
associate the DAT file with the object. "Encrypted" files are processed 
transparently, you do not need to specify the password of a file.

If the third argument (skipMemo) specified, memo field will not be 
processed at all.

=cut

sub new {
 my $self={};
 bless $self, shift;

 $self->open(@_) if @_;
 return $self;
}

=item $h->close

Close all open file handles.

=cut

sub close {
 my $self=shift;
 if($self->{fh}) {
  $self->{fh}->close();
  delete $self->{fh};
 }
 if($self->{fhMemo}) {
  $self->{fhMemo}->close();
  delete $self->{fhMemo};
 }
}

sub DESTROY {
 shift->close;
}

=item $h->open('file.dat' [, 1])

Read and parse header of Clarion file. 

If second argument given, skip processing of memo field.

=cut

sub open {
 my ($self, $fileName, $skipMemo)=@_;

 my $fh=new FileHandle $fileName
	or die("Cannot open '$fileName': $!\n");
 binmode($fh);
 $self->{fh}=$fh;

 # Read file signature & header
 my ($filesig, $sfatr)=unpack('a2 S', $self->readData(4, 'header'));
 die "Not a Clarion 2.1 file '$fileName'!\n" 	if $filesig ne 'C3';
 $self->{name}=$fileName;
 $self->{sfatr}=$sfatr;
 my $header=$self->readData(2*9+31+9*4-4, 'header');
 
 # File is encrypted?



( run in 3.215 seconds using v1.01-cache-2.11-cpan-d8267643d1d )