#!perl
# in a file: FunLib.pm
# Usage
# use FunLib qw/:all/;
# use FunLib qw/sum circle_sector_area/;
# my @nums = (10, 14, 25, 49);
# my $result = sum(@nums);
#
# What is the area of a circle sector
# with a radius of 4 and a 20 degree angle?
# my $area = circle_sector_area(4,20);
#
# Globals
# FunLib::PI
# $FunLib::level
use strict;
use warnings;
package FunLib;
use constant PI => 4 * atan2(1,1);
our $level = 10;
BEGIN {
use Exporter( );
our ($VERSION, @ISA, @EXPORT, @EXPORT_OK, %EXPORT_TAGS);
$VERSION = "1.00"; # make a version for changes
@ISA = qw/Exporter/; # inherit from Exporter
@EXPORT = ( ); # don't export without asking
# create Export tags for convenience
%EXPORT_TAGS = (
all => [ qw/ sum sum circle_sector_area PI $level / ],
calculate => [ qw/ sum circle_sector_area / ],
globals => [ qw/ PI $level / ],
);
@EXPORT_OK = qw/
sum
circle_sector_area
PI
$level
/;
}
# $result = sum(@something)
# sum @something and return $result
sub sum {
my (@something) = @_;
my $result = 0;
foreach my $item (@_) {
$result += $item;
}
return $result;
}
# $area = circle_sector_area($radius, $degrees);
# Return the area of a circle sector
# given the $radius, the angle in $degrees
# and the global constant, PI
sub circle_sector_area {
my ($radius, $degrees) = @_;
return ($radius * $radius * (PI / 360));
}
1; # enables Perl to know it loaded properly