Set the dictionary encoding of files created by the perl module.
[pspp-builds.git] / perl-module / lib / PSPP.pm
index 201e99c0576014ee58497d2e1dfdacd27cb84ced..2dccd10a36973e560e8be7d267b92f9bdb918ac1 100644 (file)
@@ -21,7 +21,7 @@ None by default.
 
 =cut
 BEGIN {
 
 =cut
 BEGIN {
-       do 'pspp-vers.pl' || die "No version set";
+       $PSPP::VERSION='0.7.2';
        require XSLoader;
        XSLoader::load('PSPP', $PSPP::VERSION);
 }
        require XSLoader;
        XSLoader::load('PSPP', $PSPP::VERSION);
 }
@@ -87,9 +87,15 @@ sub new
 
 =pod
 
 
 =pod
 
-=head3 get_var
+=head3 get_var_cnt ()
 
 
-Returns a variable from a dictionary
+Returns the number of variables in the dictionary.
+
+=head3 get_var ($idx)
+
+Returns the C<idx>th variable from the dictionary.
+Returns undef if C<idx> is greater than or equal to the number
+of variables in the dictionary.
 
 =cut
 
 
 =cut
 
@@ -106,6 +112,28 @@ sub get_var
     return $var;
 }
 
     return $var;
 }
 
+=pod
+
+=head3 get_var_by_name ($name)
+
+Returns the variable from the dictionary whose name is C<name>.
+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;
 
 
 package PSPP::Fmt;
 
@@ -169,7 +197,7 @@ package PSPP::Var;
 =head3 new ($dict, $name, %input_fmt)
 
 Creates and returns a new variable in the dictionary C<dict>.  The 
 =head3 new ($dict, $name, %input_fmt)
 
 Creates and returns a new variable in the dictionary C<dict>.  The 
-new variable will have the name C<name>.
+new variable will have the name C<name>.  C<name> must be a valid UTF8 string.
 The input format is set by the C<input_fmt> parameter 
 (See L</PSPP::Fmt>).
 By default, the write and print formats are the same as the input format.
 The input format is set by the C<input_fmt> parameter 
 (See L</PSPP::Fmt>).
 By default, the write and print formats are the same as the input format.
@@ -198,7 +226,7 @@ sub new
 
 =head3 set_label ($label)
 
 
 =head3 set_label ($label)
 
-Sets the variable label to C<label>.
+Sets the variable label to C<label>, which must be a valid UTF8 string.
 
 
 =cut
 
 
 =cut
@@ -221,7 +249,7 @@ An integer denoting the number of decimal places for the format.
 
 =item width
 
 
 =item width
 
-An integer denoting the number of width of the format.
+An integer denoting the width of the format.
 
 =back
 
 
 =back
 
@@ -254,6 +282,16 @@ sub set_print_format
 
 =pod
 
 
 =pod
 
+
+=head3 get_write_format ()
+
+Returns a reference to a hash containing the write format for the variable.
+
+
+=head3 get_print_format ()
+
+Returns a reference to a hash containing the print format for the variable.
+
 =head3 set_output_format (%fmt)
 
 Sets the write and print formats to C<fmt>.  This is the same as
 =head3 set_output_format (%fmt)
 
 Sets the write and print formats to C<fmt>.  This is the same as
@@ -284,6 +322,7 @@ Removes all value labels from the variable.
 =head3 add_value_label ($key, $label)
 
 Adds the value label C<label> to the variable for the value C<key>.
 =head3 add_value_label ($key, $label)
 
 Adds the value label C<label> to the variable for the value C<key>.
+C<label> must be a valid UTF8 string.
 On error the subroutine returns zero.
 
 =head3 add_value_labels (@array)
 On error the subroutine returns zero.
 
 =head3 add_value_labels (@array)
@@ -310,7 +349,7 @@ sub add_value_labels
 
 =pod
 
 
 =pod
 
-=head3 set_value_labels ($key, $value)
+=head3 set_value_labels ($key, $label)
 
 C<Set_value_labels> is identical to calling L</clear_value_labels>
 followed by L</add_value_labels>.
 
 C<Set_value_labels> is identical to calling L</clear_value_labels>
 followed by L</add_value_labels>.
@@ -333,8 +372,26 @@ sub set_value_labels
 Sets the missing values for the variable.  
 No more than three missing values may be specified.
 
 Sets the missing values for the variable.  
 No more than three missing values may be specified.
 
-=cut
+=head3 get_attributes()
+
+Returns a reference to a hash of the custom variable attributes.
+Each value of the hash is a reference to an array containing the 
+attribute values.
+
+=head3 get_name ()
+
+Returns the name of the variable.
+
+=head3 get_label ()
 
 
+Returns the label of the variable or undef if there is no label.
+
+=head3 get_value_labels ()
+
+Returns a reference to a hash containing the value labels for the variable.
+The hash is keyed by data values which correpond to the labels.
+
+=cut
 
 package PSPP::Sysfile;
 
 
 package PSPP::Sysfile;
 
@@ -358,6 +415,7 @@ On error, undef is returned.
 Appends a case to the system file.
 C<Case> is an array of scalars, each of which are the values of 
 the variables in the dictionary corresponding to the system file.
 Appends a case to the system file.
 C<Case> is an array of scalars, each of which are the values of 
 the variables in the dictionary corresponding to the system file.
+If the case contains strings, then the strings must be UTF8 encoded.
 The special value C<PSPP::SYSMIS> may be used to indicate that a value
 is system missing.
 If the array contains less elements than variables in the dictionary,
 The special value C<PSPP::SYSMIS> may be used to indicate that a value
 is system missing.
 If the array contains less elements than variables in the dictionary,
@@ -395,6 +453,12 @@ The system file will be automatically closed when it goes out of scope.
 
 package PSPP::Reader;
 
 
 package PSPP::Reader;
 
+=pod
+
+=head2 PSPP::Reader
+
+=cut
+
 sub open
 {
     my $class = shift;
 sub open
 {
     my $class = shift;
@@ -409,6 +473,17 @@ sub open
     return $self;
 }
 
     return $self;
 }
 
+=pod
+
+=head3 open ($filename)
+
+Opens a system file for reading.
+
+Open is used to read data from an existing system file. 
+It creates and returns a PSPP::Reader object which can be used to read 
+data and dictionary information from C<filename>.
+
+=cut
 
 sub get_dict
 {
 
 sub get_dict
 {
@@ -421,7 +496,43 @@ sub get_dict
     return $dict;
 }
 
     return $dict;
 }
 
+=pod
+
+=head3 get_dict ()
+
+Returns the dictionary associated with the reader.
+
+=head3 get_next_case ()
+
+Retrieves the next case from the reader.
+This method returns an array of scalars, each of which are the values of 
+the data in the system file.
+The first call to C<get_next_case> after C<open> has been called retrieves
+the first case in the system file.  Each subsequent call retrieves the next
+case.  If there are no more cases to be read, the function returns an empty
+list.
+
+If the case contains system missing values, these values are set to the 
+empty string.
+
+=head2 Miscellaneous subroutines
 
 
+The following subroutines provide (hopefully) useful information about the 
+values retrieved from a reader.
+
+=head3 PSPP::format_value ($value, $variable)
+
+Returns a scalar containing a string representing C<value> formatted according 
+to the print format of C<variable>.
+In the most common usage,  C<value> should be a value of C<variable>.
+
+
+=head3 PSPP::value_is_missing ($value, $variable)
+
+Returns non-zero if C<value> is either system missing, or if it matches the 
+user missing criteria for C<variable>.
+
+=cut
 
 1;
 __END__
 
 1;
 __END__
@@ -433,21 +544,19 @@ John Darrington, E<lt>john@darrington.wattle.id.auE<gt>
 
 =head1 COPYRIGHT AND LICENSE
 
 
 =head1 COPYRIGHT AND LICENSE
 
-Copyright (C) 2007 by Free Software Foundation
+Copyright (C) 2007, 2008, 2009 by Free Software Foundation
 
 
-   This program is free software; you can redistribute it and/or
-   modify it under the terms of the GNU General Public License as
-   published by the Free Software Foundation; either version 2 of the
-   License, or (at your option) any later version.
+This program is free software: you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation, either version 3 of the License, or
+(at your option) any later version.
 
 
-   This program is distributed in the hope that it will be useful, but
-   WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-   General Public License for more details.
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
 
 
-   You should have received a copy of the GNU General Public License
-   along with this program; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
-   02110-1301, USA.
+You should have received a copy of the GNU General Public License
+along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 =cut
 
 =cut