Spreadsheet::Engine::Fn::counter - base class for counting functions


Spreadsheet-Engine documentation Contained in the Spreadsheet-Engine distribution.

Index


Code Index:

NAME

Top

Spreadsheet::Engine::Fn::counter - base class for counting functions

SYNOPSIS

Top

  use base 'Spreadsheet::Engine::Fn::counter';

  sub calculate { 
    return sub { 
      my $type = shift;
      return is_match($type)
    };
  }

DESCRIPTION

Top

This provides a base class for spreadsheet functions that count the number of values in a list that match a certain type (COUNT, COUNTA, COUNTBLANK, etc).

METHODS

Top

argument_count

By default all such functions take one or more argument.

result_type

This is always a number.

TO SUBCLASS

Top

calculate

Returns a subref that is given each type in turn and returns a true/false value for whether or not it should be counted in the total.

HISTORY

Top

This is a Modified Version of code extracted from SocialCalc::Functions in SocialCalc 1.1.0

COPYRIGHT

Top

LICENCE

Top

The contents of this file are subject to the Artistic License 2.0; you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.perlfoundation.org/artistic_license_2_0


Spreadsheet-Engine documentation Contained in the Spreadsheet-Engine distribution.

package Spreadsheet::Engine::Fn::counter;

use strict;
use warnings;

use base 'Spreadsheet::Engine::Fn::base';

sub argument_count { -1 }

sub result {
  my $self = shift;

  return unless defined(my $foperand = $self->foperand);

  my $match = $self->calculate;
  my $count = 0;

  while (@{$foperand}) {
    $count++ if $match->($self->next_operand);
  }

  return Spreadsheet::Engine::Value->new(type => 'n', value => $count);
}

1;

__END__