File perl-Math-RPN.spec of Package perl-Math-RPN

#
# spec file for package perl-Math-RPN
#
# Copyright (c) 2015 SUSE LINUX GmbH, Nuernberg, Germany.
#
# All modifications and additions to the file contributed by third parties
# remain the property of their copyright owners, unless otherwise agreed
# upon. The license for this file, and modifications and additions to the
# file, is the same license as for the pristine package itself (unless the
# license for the pristine package is not an Open Source License, in which
# case the license is the MIT License). An "Open Source License" is a
# license that conforms to the Open Source Definition (Version 1.9)
# published by the Open Source Initiative.

# Please submit bugfixes or comments via http://bugs.opensuse.org/
#


Name:           perl-Math-RPN
Version:        1.11
Release:        0
%define cpan_name Math-RPN
Summary:        Perl extension for Reverse Polish Math Expression Evaluation
License:        Artistic-1.0 or GPL-1.0+
Group:          Development/Libraries/Perl
Url:            http://search.cpan.org/dist/Math-RPN/
Source0:        http://www.cpan.org/authors/id/S/SZ/SZABGAB/%{cpan_name}-%{version}.tar.gz
BuildArch:      noarch
BuildRoot:      %{_tmppath}/%{name}-%{version}-build
BuildRequires:  perl
BuildRequires:  perl-macros
BuildRequires:  perl(Test::NoWarnings)
BuildRequires:  perl(Test::Warn)
%{perl_requires}

%description
The rpn function will take a scalar or list of sclars which contain an RPN
expression as a set of comma delimited values and operators, and return the
result or stack, depending on context. If the function is called in an
array context, it will return the entire remaining stack. If it is called
in a scalar context, it will return the top item of the stack. In a scalar
context, if more than one value remains on the stack, a warning will be
sent to STDERR.

In the event of an error, an error message will be sent to STDERR, and rpn
will return undef.

The expression can contain any combination of values and operators. Any
token which is not an operator is assumed to be a value to be pushed onto
the stack.

An explanation of Reverse Polish Notation is beyond the scope of this
document, but it I will describe it briefly as a stack-based way of writing
mathematical expressions. This has the advantage of eliminating the need
for parenthesis and simplifying parsing for computers vs. normal algebraic
notation at a slight cost in the ability of humans to easily comprehend the
expressions.

This evaluator works by cycling through the expression from left to right.
As each token is encountered, it is checked against the list of operators.
If it matches, then a check is performed for stack underflow. If the stack
has not underflowed, the operation is performed by removing the required
number of operands from the top of the stack. The result is then pushed on
to the stack. Operations for which order is significant (-,/,%,etc.) are
processed such that the top item on the stack is treated as the right
operand, and the next item down is treated as the left operand. Thus,
"5,3,-" would yield 2, not -2. If the token does not match any of the known
operators, the token is blindly pushed onto the stack. As a result, one can
produce unexpected results. For example, the expression "5,3,grandma,+,*"
would produce 15 because 5*(3+0) is how it would end up evaluated. That is,
5 would be pushed onto the stack, then 3, then "grandma". Next, + is
evaluated, so 3+"grandma" is evaluated. Perl evaluates "grandma" to be
numerically 0, so 3 is pushed back onto the stack. Next, the * multiplies
the top two items of the stack [5][3], producing 15, which is pushed back
onto the stack.

%prep
%setup -q -n %{cpan_name}-%{version}

%build
%{__perl} Makefile.PL INSTALLDIRS=vendor
%{__make} %{?_smp_mflags}

%check
%{__make} test

%install
%perl_make_install
%perl_process_packlist
%perl_gen_filelist

%files -f %{name}.files
%defattr(-,root,root,755)
%doc Changes README

%changelog
openSUSE Build Service is sponsored by