blib/lib/Asterisk/LCR/Comparer.pm untested

filter: Statementstmt 0.0% 0 / 32 Branchbran n/a Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 0.0% 0 / 12 Podpod 0.0% 0 / 8 totaltotal 0.0% 0 / 62 CC 1 SCAR 6.9
CC
1
Cov
0%
normalize
2.0
sortme
2.0
eq
2.0
CRAP 2.0
1 =head1 NAME
2  
3 Asterisk::LCR::Comparer - Generic Route Comparer for Asterisk::LCR
4  
5  
6 =head1 SUMMARY
7  
8 This is a generic class for any Comparer object. Asterisk::LCR::Comparer
9 objects must implement the sortme() method for it to function properly.
10  
11  
12 =head1 ATTRIBUTES
13  
14 none.
15  
16  
17 =head1 METHODS
18  
19  
20 =cut
21 package Asterisk::LCR::Comparer;
22 use base qw /Asterisk::LCR::Object/;
23 use Config::Mini;
24 use warnings;
25 use strict;
26  
27  
28 =head2 $self->normalize ($rate);
29  
30 Turns $rate into a 1/1, base currency rate.
31  
32 =cut
33 sub normalize
34 {
35 my $self = shift;
36 my $rate = shift;
37 $rate->{first_increment} = 1;
38 $rate->{connection_fee} = 0;
39 $rate->{increment} = 1;
40 $rate->{currency} = Config::Mini::get ('comparer')->currency();
41 }
42  
43  
44 =head2 $self->sortme ($object1, $object2);
45  
46 This method needs to be implemented by subclasses.
47  
48 Should:
49  
50 =over 4
51  
52 =item return +1 if $object1 is greater than $object2
53  
54 =item return -1 if $object1 is smaller than $object2
55  
56 =item return 0 if $object1 is equal to $object2
57  
58 =back
59  
60 =cut
61 sub sortme
62 {
63 die "Asterisk::LCR::Comparer::sortme() is a virtual method";
64 }
65  
66  
67 =head2 $self->eq ($object1, $object2);
68  
69 Returns 1 if both objects are equal, 0 otherwise.
70  
71 =cut
72 sub eq
73 {
74 my $self = shift;
75 return $self->sortme (@_) == 0;
76 }
77  
78  
79 =head2 $self->ne ($object1, $object2);
80  
81 Returns 1 if both objects are not equal, 0 otherwise.
82  
83 =cut
84 sub ne
85 {
86 my $self = shift;
87 return not $self->eq (@_);
88 }
89  
90  
91 =head2 $self->gt ($object1, $object2);
92  
93 Returns 1 if $object1 is strictly greater than $object2, 0 otherwise.
94  
95 =cut
96 sub gt
97 {
98 my $self = shift;
99 return $self->sortme (@_) > 0;
100 }
101  
102  
103 =head2 $self->ge ($object1, $object2);
104  
105 Returns 1 if $object1 is greater or equals than $object2, 0 otherwise.
106  
107 =cut
108 sub ge
109 {
110 my $self = shift;
111 return $self->gt (@_) or $self->eq (@_);
112 }
113  
114  
115 =head2 $self->lt ($object1, $object2);
116  
117 Returns 1 if $object1 is strictly smaller than $object2, 0 otherwise.
118  
119 =cut
120 sub lt
121 {
122 my $self = shift;
123 return $self->sortme (@_) < 0;
124 }
125  
126  
127 =head2 $self->ge ($object1, $object2);
128  
129 Returns 1 if $object1 is smaller or equals than $object2, 0 otherwise.
130  
131 =cut
132 sub le
133 {
134 my $self = shift;
135 return $self->lt (@_) or $self->eq (@_);
136 }
137  
138  
139 1;
140  
141  
142 __END__