Spreadsheet-Engine
view release on metacpan - search on metacpan
view release on metacpan or search on metacpan
lib/Spreadsheet/Engine.pm view on Meta::CPAN
package Spreadsheet::Engine;
use strict;
use warnings;
use Spreadsheet::Engine::Sheet (
qw/parse_sheet_save execute_sheet_command recalc_sheet/);
our $VERSION = '0.14';
=head1 NAME
Spreadsheet::Engine - Core calculation engine for a spreadsheet
=head1 SYNOPSIS
use Spreadsheet::Engine;
my $sheet = Spreadsheet::Engine->new;
my $sheet = Spreadsheet::Engine->load_data([@data]);
$sheet->execute('set A1 value n 2');
$sheet->execute('set A2 value n 4');
$sheet->execute('set A3 formula SUM(A1:A2)');
$sheet->recalc;
my $data = $sheet->raw;
print $data->{datavalues}{A3}; # 6
=head1 DESCRIPTION
This provides back-end spreadsheet functionality for creating a
sheet, setting cells to have values or formulae, and performing all
necessary calculations. There is no front-end UI provided - this
is purely the calculation engine.
Over 110 spreadsheet functions are provided: see
Spreadsheet::Engine::Function::* and L<Spreadsheet::Engine::Functions>
for the full list.
=head1 METHODS
=head2 new
my $sheet = Spreadsheet::Engine->new;
Instantiate a new blank spreadsheet.
=cut
sub _new {
my $class = shift;
bless { _sheet => {} } => $class;
}
sub new {
my $class = shift;
return $class->load_data([]);
}
=head2 load_data
my $sheet = Spreadsheet::Engine->load_data([@data]);
Instantiate a sheet from lines of data in the saved file format (see
L<Spreadsheet::Engine::Sheet> for documentation)
=cut
sub load_data {
my ($class, $data) = @_;
my $self = $class->_new;
parse_sheet_save($data => $self->{_sheet});
return $self;
}
=head2 execute
$sheet->execute('set A1 value n 2');
$sheet->execute('set A2 value n 4');
$sheet->execute('set A3 formula SUM(A1:A2)');
Execute the given command against the sheet. See
L<Spreadsheet::Engine::Sheet> for documentation of commands.
=cut
sub execute {
my ($self, $command) = @_;
execute_sheet_command($self->{_sheet} => $command);
return $self;
}
=head2 recalc
$sheet->recalc;
Recalculate the values for all formulae in the sheet. This never happens
automatically - it must be explicitly called.
=cut
sub recalc {
my $self = shift;
recalc_sheet($self->{_sheet});
return $self;
}
=head2 raw
my $data = $sheet->raw;
print $data->{datavalues}{A3}; # 6
view all matches for this distributionview release on metacpan - search on metacpan
( run in 1.271 second using v1.00-cache-2.02-grep-82fe00e-cpan-9f2165ba459b )