<<

NAME

Koha::CSV - Wrapper around Text::CSV_XS with Koha-specific defaults

SYNOPSIS

    my $csv = Koha::CSV->new();
    $csv->combine(@fields);
    my $line = $csv->string();

    # Override defaults
    my $csv = Koha::CSV->new( { sep_char => ';', always_quote => 1 } );

DESCRIPTION

This class wraps Text::CSV_XS providing consistent defaults and methods used across Koha for CSV generation and parsing.

Configuration is inherited from Koha system preferences where applicable, but can be overridden per instance.

Configuration Inheritance

new

    my $csv = Koha::CSV->new();
    my $csv = Koha::CSV->new({ sep_char => ';', always_quote => 1 });

Creates a new Koha::CSV object. Accepts optional parameters to override defaults.

Parameters: - sep_char: CSV delimiter (defaults to CSVDelimiter system preference) - always_quote: Whether to quote all fields (defaults to 0) - eol: End of line character (defaults to "\n")

Note: binary and formula parameters are fixed for security and cannot be overridden.

combine

    $csv->combine(@fields);

Combines fields into a CSV line. Returns true on success.

string

    my $line = $csv->string();

Returns the combined CSV line as a string.

add_row

    my $line = $csv->add_row(@fields);
    # or
    my $line = $csv->add_row(\@fields);

Convenience method that combines fields and returns the CSV line as a string. Accepts either an array or arrayref of fields.

parse

    $csv->parse($line);

Parses a CSV line. Returns true on success.

fields

    my @fields = $csv->fields();

Returns the parsed fields from the last parse() call.

print

    $csv->print($fh, \@fields);

Prints fields to a filehandle as a CSV line.

getline

    my $fields = $csv->getline($fh);

Reads and parses a line from a filehandle. Returns arrayref of fields.

error_diag

    my $error = $csv->error_diag();

Returns error diagnostics from the last operation.

<<