NAME

Salus - checksummed csvs

VERSION

Version 0.08

SYNOPSIS

package Corruption;

use Salus all => 1;

header id => (
	label => 'ID',
);

header firstName => (
	label => 'First Name',
);

header lastName => (
	label => 'Last Name',
);

header header => (
	label => 'Age',
);

1;

...

my $unethical = Corruption->new(
	file => 't/test.csv',
	unprotected_read => 1
);

$unethical->read();

$unethical->write('t/test2.csv');

ATTRIBUTES

file

The file to be read

secret

The secret used for the hmac

unprotected_read

Set if you would like to read an unprotected csv

headers

The headers used for parsing and writing the csv

rows

The data stored in the Salus object

METHODS

new

my $salus = Salus->new({
	secret => 'xyz',
	headers => [
		{
			name => 'id',
			label => 'ID'
		},
		...
	]
});

$salus->add_rows([
	[1, 'Robert', 'Acock', 32],
	[2, 'Jack', 'Joy', 33],
	[3, 'Pluto', 'Hades', 34]
]);

$salus->combine('t/test.csv', 'id');

$salus->get_row(2)->as_array;

read

Read a Salus csv file into memory, the function accepts two params the first is a filename, the second is optional and if a true value is passed the rows will be returned without them being cached inside of Salus itself.

$salus->read('test.csv');

Note: if your csv was not generated using salus then you will want to enable "unprotected_read" first.

combine

Combine another csv with the existing data stored in the Salus object, the function expects two params the first is a filename, the second is the column on which to overwrite the rows value if there is a match.

$salus->combine('testing.csv', 'id');

write

Write the Salus data to a csv file.

$salus->write("new.csv");

count

Returns the total number of rows stored in the Salus object.

$salus->count;

add_row

Add a single row to the Salus object.

$salus->add_row([
	1, 'Robert', 'Acock', 32
]);

add_rows

Add multiple rows to the Salus object.

$salus->add_rows([
	[2, 'Jack', 'Joy', 33],
	[3, 'Pluto', 'Hades', 34]
]);

add_row_hash

Add a single row to the Salus object passing the data as a hash

$salus->add_row_hash({
	id => 1, 
	...
});

get_row

Get a single row. This function expects a single param that represents the row index you would like to get.

$salus->get_row(0);

get_row_col

Get a single row column. This function expects two params that represent the row index and the column index or name you would like to get.

$salus->get_row_col(0, 1);

set_row

Set a single row. This function expects two params the first that represents the row index to update and the second that is an arrayref representing column values to update.

$salus->set_row(0, [1, 'Robert', 'Acock', 32]);

set_row_col

Set a single rows column value. This function expects three params the first that represents the row index, the second a column index or name and finally the third which should contain the value that will be used to update the rows column.

$salus->set_row_col(0, 3, 33);

delete_row

Delete a single row. This function expects a single param that represents the row index you would like to delete.

$salus->delete_row(0);

delete_row_col

Delete a single row column. This function expects two params that represent the row index and the column index or name you would like to clear.

$salus->delete_row_col(0, 1);

sort

Sort the Salus object rows. This function expects three params, the column index or name, the order to sort and a boolean value to toggle whether or not to store the results in the sorted order.

$salus->sort(1, 'asc'); # will store the sorted rows
$salus->sort(1, 'desc', 1); # will only return the sorted rows

Search the Salus object rows. This function expects two params, the column index or name to search and the string to search for. It will return all matches within the stored rows.

$salus->search('firstName', 'Robert'); 

find

Search the Salus object row index. This function expects two params, the column index or name to search and the string to search for. It will return the first matches row index.

$salus->find('firstName', 'Robert');

find_column_index

Find the column index by column header name.

$salus->find_column_index('firstName');

sum

Perform a sum aggregation on a column.

$salus->sum('age');

mean

Perform a mean aggregation on a column.

$salus->mean('age');

median

Perform a median aggregation on a column.

$salus->median('age'); # returns the value
$salus->median('age', 1); # returns the row

mode

Perform a mode aggregation on a column.

$salus->mode('age');

min

Find the minimum value for a column

$salus->min('age'); # returns the value
$salus->min('age', 1); # returns the row

max

Find the miximum value for a column

$salus->max('age'); # returns the value
$salus->max('age', 1); # returns the row

headers_as_array

Returns all headers stringified as label || name as an arrayref.

$salus->headers_as_array;

headers_stringify

Returns all headers stringified including label, name and index as an arrayref.

$salus->headers_stringify;

diff_files

Diff two files using Text::Diff.

$salus->diff_files($file1, $file2);

AUTHOR

LNATION, <email at lnation.org>

BUGS

Please report any bugs or feature requests to bug-salus at rt.cpan.org, or through the web interface at https://rt.cpan.org/NoAuth/ReportBug.html?Queue=Salus. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.

SUPPORT

You can find documentation for this module with the perldoc command.

perldoc Salus

You can also look for information at:

ACKNOWLEDGEMENTS

LICENSE AND COPYRIGHT

This software is Copyright (c) 2024 by LNATION.

This is free software, licensed under:

The Artistic License 2.0 (GPL Compatible)