| 1 | package Proc::BackOff::Exponential; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | # Inheritance | ||||||||||||||||||||||||||||
| 4 | 2 | ▶ | use base qw( Proc::BackOff ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | # Set up get/set fields | ||||||||||||||||||||||||||||
| 7 | # 2 ^ 5 | ||||||||||||||||||||||||||||
| 8 | # 2 is the base | ||||||||||||||||||||||||||||
| 9 | # 5 is the exponent | ||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | 2 | __PACKAGE__->mk_accessors( 'base', | |||||||||||||||||||||||||||
| 12 | 'exponent', | ||||||||||||||||||||||||||||
| 13 | ); | ||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | # standard pragmas | ||||||||||||||||||||||||||||
| 16 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 17 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | # standard perl modules | ||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | # CPAN & others | ||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | 2 | our $VERSION = '0.01'; | |||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | =head1 NAME | ||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | Proc::BackOff::Exponential | ||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | Usage: | ||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | use Proc::BackOff::Exponential; | ||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | my $obj = Proc::BackOff::Exponential->new( { base => 2 , exponent=> 'count' } ); | ||||||||||||||||||||||||||||
| 36 | # On N'th failure delay would be set to: | ||||||||||||||||||||||||||||
| 37 | # 1st failure : 2^1 = 2 | ||||||||||||||||||||||||||||
| 38 | # 2nd failure : 2^2 = 4 | ||||||||||||||||||||||||||||
| 39 | # 3rd failure : 2^3 = 8 | ||||||||||||||||||||||||||||
| 40 | # 4th failure : 2^4 = 16 | ||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | # or | ||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | my $obj = Proc::BackOff::Exponential->new( { base => 'count' , exponent=> 2 } ); | ||||||||||||||||||||||||||||
| 45 | # On N'th failure delay would be set to: | ||||||||||||||||||||||||||||
| 46 | # 1st failure : 1^2 = 1 | ||||||||||||||||||||||||||||
| 47 | # 2nd failure : 2^2 = 4 | ||||||||||||||||||||||||||||
| 48 | # 3rd failure : 3^2 = 9 | ||||||||||||||||||||||||||||
| 49 | # 4th failure : 4^2 = 16 | ||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | See L<Proc::BackOff> for further documentation. | ||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | =head1 Overloaded Methods | ||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | =head2 new() | ||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | Check for variables being set | ||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | Required: base | ||||||||||||||||||||||||||||
| 60 | Required: exponent | ||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | =cut | ||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | 2 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=6 SCAR=24.1
Pod
documented
| |||||||||||||||||||||||||||||
| 65 | 2 | my $proto = shift; | |||||||||||||||||||||||||||
| 66 | 2 | ▶ | my $class = ref $proto || $proto; | ||||||||||||||||||||||||||
|
Condition33%1/3
ref $proto || $proto
MC/DC0%0/2
ref $proto || $proto
ref $proto
$proto
Truth table33%1/3
A || B
A= ref $protoB= $proto
| |||||||||||||||||||||||||||||
| 67 | 2 | my $obj = $class->SUPER::new(@_); | |||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | 2 | ▶ | if ( ! defined $obj->exponent() || ! $obj->valid_number_check($obj->exponent())) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $obj->exponent and $obj->valid_number_check($obj->exponent)
MC/DC0%0/2
defined $obj->exponent and $obj->valid_number_check($obj->exponent)
defined $obj->exponent
$obj->valid_number_check($obj->exponent)
Truth table33%1/3
A and B
A= defined $obj->exponentB= $obj->valid_number_check($obj->exponent)
| |||||||||||||||||||||||||||||
| 70 | 0 | warn "$proto: Exponent value not set"; | |||||||||||||||||||||||||||
| 71 | 0 | return undef; | |||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | 2 | ▶ | if ( ! defined $obj->base() || ! $obj->valid_number_check($obj->base())) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $obj->base and $obj->valid_number_check($obj->base)
MC/DC0%0/2
defined $obj->base and $obj->valid_number_check($obj->base)
defined $obj->base
$obj->valid_number_check($obj->base)
Truth table33%1/3
A and B
A= defined $obj->baseB= $obj->valid_number_check($obj->base)
| |||||||||||||||||||||||||||||
| 75 | 0 | warn "$proto: Base value not set"; | |||||||||||||||||||||||||||
| 76 | 0 | return undef; | |||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | 2 | return $obj; | |||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||
| 82 | =head2 calculate_back_off() | ||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | Returns the new back off value. | ||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||
| 86 | =cut | ||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||
| 88 | 20 | ▶ | sub calculate_back_off { | ||||||||||||||||||||||||||
|
Subroutine
calculate_back_off: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||
| 89 | 20 | my $self = shift; | |||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | # this is an exponential back off | ||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||
| 93 | 20 | my $exponent = $self->exponent(); | |||||||||||||||||||||||||||
| 94 | 20 | my $base = $self->base(); | |||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||
| 96 | 20 | ▶ | $exponent = $self->failure_count() if $exponent eq 'count'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 97 | 20 | ▶ | $base = $self->failure_count() if $base eq 'count'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||
| 99 | 20 | return $base ^ $exponent; | |||||||||||||||||||||||||||
| 100 | } | ||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||
| 102 | =cut | ||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||
| 104 | 1; | ||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||
| 106 | =head1 Changes | ||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||
| 108 | 0.02 2007-08-12 -- Daniel Lo | ||||||||||||||||||||||||||||
| 109 | - Documentation fixes. No code changes. | ||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||
| 111 | 0.01 2007-04-17 -- Daniel Lo | ||||||||||||||||||||||||||||
| 112 | - Initial Version | ||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||
| 114 | =head1 AUTHOR | ||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||
| 116 | Daniel Lo <daniel_lo@picturetrail.com> | ||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||
| 118 | =head1 LICENSE | ||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||
| 120 | Copyright (C) PictureTrail Inc. 1999-2007 | ||||||||||||||||||||||||||||
| 121 | Santa Clara, California, United States of America. | ||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||
| 123 | This code is released to the public for public use under Perl's Artisitic | ||||||||||||||||||||||||||||
| 124 | licence. | ||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||
| 126 | =cut | ||||||||||||||||||||||||||||