| 1 | #!/usr/bin/perl | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | package Language::Farnsworth; | ||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | 4 | our $VERSION = "0.7.7"; | |||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 4 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 4 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | 4 | ▶ | use Language::Farnsworth::Evaluate; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 4 | ▶ | use Language::Farnsworth::Value; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | 4 | ▶ | use Language::Farnsworth::Dimension; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | 4 | ▶ | use Language::Farnsworth::Units; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | 4 | ▶ | use Language::Farnsworth::FunctionDispatch; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 15 | 4 | ▶ | use Language::Farnsworth::Variables; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 16 | 4 | ▶ | use Language::Farnsworth::Output; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 17 | 4 | ▶ | use Math::Pari; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | 4 | ▶ | use Data::Dumper; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | sub new | ||||||||||||||||||||||||||||
| 22 | 4 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 23 | 4 | shift; #get the class off | |||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | 4 | my $self = {}; | |||||||||||||||||||||||||||
| 26 | 4 | my @modules = @_; #i get passed a list of modules to use for standard stuff; | |||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | 4 | Math::Pari::setprecision(100); #both of these need to be user configurable! | |||||||||||||||||||||||||||
| 29 | 4 | Math::Pari::allocatemem(40_000_000); | |||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | 4 | ▶ | if (@modules < 1) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 32 | { | ||||||||||||||||||||||||||||
| 33 | 4 | @modules = ("Units::Standard", "Functions::Standard", "Functions::StdMath", "Functions::GoogleTranslate", "Units::Currency"); #standard modules to include | |||||||||||||||||||||||||||
| 34 | } | ||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | #print Dumper(\@modules); | ||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | 4 | $self->{eval} = Language::Farnsworth::Evaluate->new(); | |||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | 4 | for my $a (@modules) | |||||||||||||||||||||||||||
| 41 | { | ||||||||||||||||||||||||||||
| 42 | 20 | local $@; | |||||||||||||||||||||||||||
| 43 | 0 | ▶ | eval 'use Language::Farnsworth::'.$a.'; Language::Farnsworth::'.$a.'::init($self->{eval});'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 44 | #die $@ if $@; | ||||||||||||||||||||||||||||
| 45 | #print "-------FAILED? $a\n"; | ||||||||||||||||||||||||||||
| 46 | #print $@; | ||||||||||||||||||||||||||||
| 47 | #print "\n"; | ||||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | 4 | bless $self; | |||||||||||||||||||||||||||
| 51 | 4 | return $self; | |||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | sub runString | ||||||||||||||||||||||||||||
| 55 | 92 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
runString: called CC=3 SCAR=11.1
Pod
documented
| |||||||||||||||||||||||||||||
| 56 | 92 | my $self = shift; | |||||||||||||||||||||||||||
| 57 | 92 | my @torun = @_; # we can run an array | |||||||||||||||||||||||||||
| 58 | 92 | my @results; | |||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | 92 | push @results, new Language::Farnsworth::Output($self->{eval}{units},$self->{eval}->eval($_), $self->{eval}) for (@torun); | |||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | 84 | ▶ | return wantarray ? @results : $results[-1]; #return all of them in array context, only the last in scalar context | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | sub runFile | ||||||||||||||||||||||||||||
| 66 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
runFile: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||||||||||||||||
| 67 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 68 | 0 | my $filename = shift; | |||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | #my @results; #i should really probably only store them all IF they are needed | ||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | 0 | ▶ | open(my $fh, "<", $filename) or die "couldn't open: $!"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 73 | 0 | my $lines; | |||||||||||||||||||||||||||
| 74 | 0 | my $first = 1; | |||||||||||||||||||||||||||
| 75 | 0 | ▶ | while(<$fh>) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 76 | { | ||||||||||||||||||||||||||||
| 77 | 0 | ▶ | $first=0, next if ($first && $_ =~ /^#!/); #skip a shebang line, not part of the language but makes it possible to have executable .frns files! | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$first and $_ =~ /^#!/
MC/DC0%0/2
$first and $_ =~ /^#!/
$first
$_ =~ /^#!/
Truth table0%0/3
A and B
A= $firstB= $_ =~ /^#!/
| |||||||||||||||||||||||||||||
| 78 | 0 | $lines .= $_; | |||||||||||||||||||||||||||
| 79 | } | ||||||||||||||||||||||||||||
| 80 | 0 | close($fh); | |||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||
| 82 | #as much as i would like this to work WITHOUT this i need to filter blank lines out #not as sure i need to do this anymore! need tests to check | ||||||||||||||||||||||||||||
| 83 | 0 | $lines =~ s/\s*\n\s*\n\s*/\n/; | |||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | 0 | return new Language::Farnsworth::Output($self->{eval}{units},$self->{eval}->eval($lines), $self->{eval}); | |||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | # while(<$fh>) | ||||||||||||||||||||||||||||
| 88 | # { | ||||||||||||||||||||||||||||
| 89 | # chomp; | ||||||||||||||||||||||||||||
| 90 | #s|//.*$||; | ||||||||||||||||||||||||||||
| 91 | #s|\s*$||; | ||||||||||||||||||||||||||||
| 92 | # } | ||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||
| 94 | # close($fh); | ||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||
| 96 | #return wantarray ? @results : $results[-1]; #return all of them in array context, only the last in scalar context | ||||||||||||||||||||||||||||
| 97 | } | ||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||
| 99 | #this will wrap around a lot of the funky code for creating a nice looking output | ||||||||||||||||||||||||||||
| 100 | #sub prettyOut | ||||||||||||||||||||||||||||
| 101 | #{ | ||||||||||||||||||||||||||||
| 102 | # my $self = shift; | ||||||||||||||||||||||||||||
| 103 | # my $input = shift; | ||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||
| 105 | # return $input->toperl($self->{eval}{units}); | ||||||||||||||||||||||||||||
| 106 | #} | ||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||
| 108 | 4 | 1; | |||||||||||||||||||||||||||
| 109 | __END__ | ||||||||||||||||||||||||||||