| 1 | package ath; | ||||||||||||||
| 2 | 1 | ▶ | use strict; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 3 | 1 | ▶ | use warnings; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 4 | 1 | ▶ | use Math::Calc::Parser; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 5 | 1 | ▶ | use Encode (); | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 6 | 1 | our $VERSION = '1.005'; | |||||||||||||
| 7 | 1 | my ($bignum, $bigrat); | |||||||||||||
| 8 | 4 | ▶ | sub import { | ||||||||||||
|
Subroutine
import: called CC=4 SCAR=23.7
| |||||||||||||||
| 9 | 4 | my $class = shift; | |||||||||||||
| 10 | 4 | foreach my $opt (@_) { | |||||||||||||
| 11 | 0 | ▶ | $bignum = 1 if $opt eq '-bignum'; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 12 | 0 | ▶ | $bigrat = 1 if $opt eq '-bigrat'; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 13 | } | ||||||||||||||
| 14 | } | ||||||||||||||
| 15 | sub unimport { $bignum = $bigrat = undef } | ||||||||||||||
| 16 | 1 | ▶ | use Filter::Simple sub { | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.1
Subroutine
__ANON__: called CC=3 SCAR=11.7
| |||||||||||||||
| 17 | 4 | my $expr = quotemeta Encode::decode 'UTF-8', "$_", Encode::FB_CROAK | Encode::LEAVE_SRC; | |||||||||||||
| 18 | 4 | ▶ | my $opts = $bigrat ? 'bigrat => 1' : $bignum ? 'bignum => 1' : ''; | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 19 | 4 | $_ = "use utf8; print Math::Calc::Parser->new($opts)->evaluate(qq{$expr}), qq{\n};" | |||||||||||||
| 20 | 1 | }; | |||||||||||||
| 21 | 1 | 1; | |||||||||||||
| 22 | |||||||||||||||
| 23 | =encoding utf8 | ||||||||||||||
| 24 | |||||||||||||||
| 25 | =head1 NAME | ||||||||||||||
| 26 | |||||||||||||||
| 27 | ath - Evaluate mathematical expressions in a compact one-liner | ||||||||||||||
| 28 | |||||||||||||||
| 29 | =head1 SYNOPSIS | ||||||||||||||
| 30 | |||||||||||||||
| 31 | $ perl -Math -e'2+2' | ||||||||||||||
| 32 | $ perl -Math -e'5!' | ||||||||||||||
| 33 | $ perl -Math -e'round e^(i*pi)' | ||||||||||||||
| 34 | $ perl -Math -e'log 5rand' | ||||||||||||||
| 35 | $ perl -Math -e'2π' | ||||||||||||||
| 36 | $ perl -Math=-bignum -e'30!' | ||||||||||||||
| 37 | $ perl -Math=-bigrat -e'3/9' | ||||||||||||||
| 38 | |||||||||||||||
| 39 | =head1 DESCRIPTION | ||||||||||||||
| 40 | |||||||||||||||
| 41 | A source filter that parses and evaluates the source code as a mathematical | ||||||||||||||
| 42 | expression using L<Math::Calc::Parser>, and prints the result. The C<-bignum> | ||||||||||||||
| 43 | or C<-bigrat> flags may be passed to activate the corresponding option. | ||||||||||||||
| 44 | |||||||||||||||
| 45 | =head1 BUGS | ||||||||||||||
| 46 | |||||||||||||||
| 47 | Report any issues on the public bugtracker. | ||||||||||||||
| 48 | |||||||||||||||
| 49 | =head1 AUTHOR | ||||||||||||||
| 50 | |||||||||||||||
| 51 | Dan Book, C<dbook@cpan.org> | ||||||||||||||
| 52 | |||||||||||||||
| 53 | =head1 COPYRIGHT AND LICENSE | ||||||||||||||
| 54 | |||||||||||||||
| 55 | Copyright 2015, Dan Book. | ||||||||||||||
| 56 | |||||||||||||||
| 57 | This library is free software; you may redistribute it and/or modify it under | ||||||||||||||
| 58 | the terms of the Artistic License version 2.0. | ||||||||||||||
| 59 | |||||||||||||||
| 60 | =head1 SEE ALSO | ||||||||||||||
| 61 | |||||||||||||||
| 62 | L<Math::Calc::Parser> | ||||||||||||||