use 5.008008; use strict; use warnings; =head1 NAME PSPP-Perl - Perl extension to PSPP =head1 SYNOPSIS use PSPP; =head1 DESCRIPTION PSPP-Perl provides an interface to the libraries used by pspp to read and write system files. =head1 EXPORT None by default. =cut BEGIN { $PSPP::VERSION='@VERSION_FOR_PERL@'; require XSLoader; XSLoader::load('PSPP', $PSPP::VERSION); } PSPP::onBoot($PSPP::VERSION); =pod =head1 PROGRAMMER'S INTERFACE The subroutines in this package return zero or unref on error. When errors occur, a string describing the error is written to C<$PSPP::errstr>. =cut package PSPP; use POSIX ; use constant { SYSMIS => -(POSIX::DBL_MAX), PERL_EPOCH => 12219379200 # Number of seconds between # 14th October 1582 # and # 1st January 1970 }; package PSPP::Dict; =pod =head2 PSPP::Dict::new Creates a new dictionary. This returned dictionary will be empty. Returns undef on failure. =head3 set_documents ($string) Sets the documents (comments) to C. =head3 add_document ($string) Appends C to the documents. =head3 clear_documents () Removes all documents. =head3 set_weight ($var) Sets the weighting variable to C. =cut sub new { my $class = shift; my $self = pxs_dict_new (); bless ($self, $class); return $self; } =pod =head3 get_var_cnt () Returns the number of variables in the dictionary. =head3 get_var ($idx) Returns the Cth variable from the dictionary. Returns undef if C is greater than or equal to the number of variables in the dictionary. =cut sub get_var { my $dict = shift; my $idx = shift; my $var = pxs_get_variable ($dict, $idx); if ( ref $var ) { bless ($var, "PSPP::Var"); } return $var; } =pod =head3 get_var_by_name ($name) Returns the variable from the dictionary whose name is C. If there is no such variable, a null reference will be returned. =cut sub get_var_by_name { my $dict = shift; my $name = shift; my $var = pxs_get_var_by_name ($dict, $name); if ( ref $var ) { bless ($var, "PSPP::Var"); } return $var; } package PSPP::Fmt; =pod =head2 PSPP::Fmt Contains constants used to denote variable format types. The identifiers are the same as those used in pspp to denote formats. For example C defines floating point format, and C denotes string format. =cut # These must correspond to the values in src/data/format.h use constant { F => 0, COMMA => 1, DOT => 2, DOLLAR => 3, PCT => 4, E => 5, CCA => 6, CCB => 7, CCC => 8, CCD => 9, CCE => 10, N => 11, Z => 12, P => 13, PK => 14, IB => 15, PIB => 16, PIBHEX => 17, RB => 18, RBHEX => 19, DATE => 20, ADATE => 21, EDATE => 22, JDATE => 23, SDATE => 24, QYR => 25, MOYR => 26, WKYR => 27, DATETIME => 28, TIME => 29, DTIME => 30, WKDAY => 31, MONTH => 32, A => 33, AHEX => 34 }; =head2 PSPP::Var =cut package PSPP::Var; =head3 new ($dict, $name, %input_fmt) Creates and returns a new variable in the dictionary C. The new variable will have the name C. C must be a valid UTF8 string. The input format is set by the C parameter (See L). By default, the write and print formats are the same as the input format. The write and print formats may be changed (See L), L). The input format may not be changed after the variable has been created. If the variable cannot be created, undef is returned. =cut sub new { my $class = shift; my $dict = shift; my $name = shift; my %format = @_; my $self = pxs_dict_create_var ($dict, $name, \%format); if ( ref $self ) { bless ($self, $class); } return $self; } =pod =head3 set_label ($label) Sets the variable label to C