File Coverage

blib/lib/Number/Closest/XS.pm
Criterion Covered Total %
statement 9 9 100.0
branch n/a
condition n/a
subroutine 3 3 100.0
pod n/a
total 12 12 100.0


line stmt bran cond sub pod time code
1             package Number::Closest::XS;
2 2     2   139664 use strict;
  2         4  
  2         130  
3 2     2   13 use warnings;
  2         5  
  2         348  
4             our $VERSION = "0.08";
5             my $XS_VERSION = $VERSION;
6             $VERSION = eval $VERSION;
7              
8             require XSLoader;
9             XSLoader::load( "Number::Closest::XS", $XS_VERSION );
10              
11 2     2   13 use base 'Exporter';
  2         8  
  2         458  
12             our @EXPORT_OK = qw(find_closest_numbers find_closest_numbers_around);
13             our %EXPORT_TAGS = (all => [@EXPORT_OK]);
14              
15             =head1 NAME
16              
17             Number::Closest::XS - find numbers closest to a given
18              
19             =head1 VERSION
20              
21             This document describes Number::Closest::XS version 0.08
22              
23             =head1 SYNOPSIS
24              
25             use Number::Closest::XS qw(:all);
26             my $res = find_closest_numbers($num, \@list, $amount);
27             my $res2 = find_closest_numbers_around($num, \@list, $amount);
28              
29             =head1 DESCRIPTION
30              
31             Module provides functions to extract from the list numbers closest to the
32             given.
33              
34             =head1 SUBROUTINES
35              
36             =head2 find_closest_numbers($num, \@list, [$amount])
37              
38             selects from the I<@list> up to I<$amount> numbers closest to the I<$num>. If
39             I<$amount> is not specified, is assumed to be 1. Returns reference to the
40             array containing found numbers sorted by the distance from the I<$num>.
41             Distance between C<$num> and C<$x> computed as C.
42              
43             =head2 find_closest_numbers_around($num, \@list, [$amount])
44              
45             selects from the I<@list> up to I<$amount> numbers closest to the I<$num>.
46             Tries to select equal amounts of numbers from both sides of the I<$num>, but if
47             there are not enough numbers from one side will select more numbers from the
48             other. If I<$amount> is odd, then the last number will be closest to I<$num>,
49             e.g. if $num is 5, @list is 1, 2, 6, 7, and amount is 3 it will return 2, 6,
50             and 7, because 7 is closer to 5 than 1. If I<$amount> is not specified, is
51             assumed to be 2. Returns reference to the array containing closest numbers
52             sorted by their values.
53              
54             =cut
55              
56             1;
57              
58             __END__