Spreadsheet::Engine::Function::EXACT - Spreadsheet funtion EXACT()


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

Index


Code Index:

NAME

Top

Spreadsheet::Engine::Function::EXACT - Spreadsheet funtion EXACT()

SYNOPSIS

Top

  =EXACT(value1, value2)

DESCRIPTION

Top

Are both valus the same, using case-sensitive text comparison.

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::Function::EXACT;

use strict;
use warnings;

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

sub argument_count { 2 }

sub calculate {
  my $self = shift;

  # Sort values by type so we only need to compare in one direction
  my ($X, $Y) =
    sort { $a->type cmp $b->type } ($self->next_operand, $self->next_operand);

  die $X if $X->is_error;
  die $Y if $Y->is_error;

  if ($X->is_blank) {
    return 1                 if $Y->is_blank;
    return !length $Y->value if $Y->is_txt;
  }

  if ($X->is_num) {
    return $X->value == $Y->value if $Y->is_num;
    return $X->value . '' eq $Y->value if $Y->is_txt;
  }

  if ($X->is_txt) {
    return $X->value eq $Y->value if $Y->is_txt;
  }

  return 0;
}

1;

__END__