| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | package Geo::Coder::Many::Scheduler::OrderedList; | 
| 2 |  |  |  |  |  |  |  | 
| 3 | 2 |  |  | 2 |  | 11 | use strict; | 
|  | 2 |  |  |  |  | 4 |  | 
|  | 2 |  |  |  |  | 69 |  | 
| 4 | 2 |  |  | 2 |  | 9 | use warnings; | 
|  | 2 |  |  |  |  | 7 |  | 
|  | 2 |  |  |  |  | 61 |  | 
| 5 |  |  |  |  |  |  |  | 
| 6 | 2 |  |  | 2 |  | 11 | use base 'Geo::Coder::Many::Scheduler'; | 
|  | 2 |  |  |  |  | 5 |  | 
|  | 2 |  |  |  |  | 844 |  | 
| 7 |  |  |  |  |  |  |  | 
| 8 |  |  |  |  |  |  | our $VERSION = '0.01'; | 
| 9 |  |  |  |  |  |  |  | 
| 10 |  |  |  |  |  |  | =head1 NAME | 
| 11 |  |  |  |  |  |  |  | 
| 12 |  |  |  |  |  |  | Geo::Coder::Many::Scheduler::OrderedList - Ordered list scheduler | 
| 13 |  |  |  |  |  |  |  | 
| 14 |  |  |  |  |  |  | =head1 DESCRIPTION | 
| 15 |  |  |  |  |  |  |  | 
| 16 |  |  |  |  |  |  | This is a scheduler representing a strict preferential order - it will always | 
| 17 |  |  |  |  |  |  | use the first geocoder in the list, unless it fails, in which case it'll fall | 
| 18 |  |  |  |  |  |  | back to the second in the list, and then the third, and so on. | 
| 19 |  |  |  |  |  |  |  | 
| 20 |  |  |  |  |  |  | =head1 METHODS | 
| 21 |  |  |  |  |  |  |  | 
| 22 |  |  |  |  |  |  | =head2 new | 
| 23 |  |  |  |  |  |  |  | 
| 24 |  |  |  |  |  |  | =cut | 
| 25 |  |  |  |  |  |  |  | 
| 26 |  |  |  |  |  |  | sub new { | 
| 27 | 140 |  |  | 140 | 1 | 198 | my $class = shift; | 
| 28 | 140 |  |  |  |  | 192 | my $ra_items = shift; | 
| 29 |  |  |  |  |  |  |  | 
| 30 | 210 |  |  |  |  | 628 | my @names = | 
| 31 | 70 |  |  |  |  | 236 | map { $_->{name} } | 
| 32 | 140 |  |  |  |  | 525 | sort { $b->{weight} <=> $a->{weight}; } @$ra_items; | 
| 33 |  |  |  |  |  |  |  | 
| 34 | 140 |  |  |  |  | 441 | my $self = { items => \@names }; | 
| 35 | 140 |  |  |  |  | 425 | bless $self, $class; | 
| 36 |  |  |  |  |  |  |  | 
| 37 | 140 |  |  |  |  | 287 | $self->reset_available(); | 
| 38 |  |  |  |  |  |  |  | 
| 39 | 140 |  |  |  |  | 482 | return $self; | 
| 40 |  |  |  |  |  |  | } | 
| 41 |  |  |  |  |  |  |  | 
| 42 |  |  |  |  |  |  | =head2 reset_available | 
| 43 |  |  |  |  |  |  |  | 
| 44 |  |  |  |  |  |  | Resets the list back to how it was initially set. | 
| 45 |  |  |  |  |  |  |  | 
| 46 |  |  |  |  |  |  | =cut | 
| 47 |  |  |  |  |  |  |  | 
| 48 |  |  |  |  |  |  | sub reset_available { | 
| 49 | 840 |  |  | 840 | 1 | 981 | my $self = shift; | 
| 50 | 840 |  |  |  |  | 835 | @{$self->{ available_items }} = @{$self->{items}}; | 
|  | 840 |  |  |  |  | 2239 |  | 
|  | 840 |  |  |  |  | 1340 |  | 
| 51 | 840 |  |  |  |  | 1748 | return; | 
| 52 |  |  |  |  |  |  | } | 
| 53 |  |  |  |  |  |  |  | 
| 54 |  |  |  |  |  |  | =head2 get_next_unique | 
| 55 |  |  |  |  |  |  |  | 
| 56 |  |  |  |  |  |  | Returns the next item in the list. | 
| 57 |  |  |  |  |  |  |  | 
| 58 |  |  |  |  |  |  | =cut | 
| 59 |  |  |  |  |  |  |  | 
| 60 |  |  |  |  |  |  | sub get_next_unique { | 
| 61 | 2005 |  |  | 2005 | 1 | 2386 | my $self = shift; | 
| 62 | 2005 |  |  |  |  | 1998 | return shift @{$self->{ available_items }}; | 
|  | 2005 |  |  |  |  | 5578 |  | 
| 63 |  |  |  |  |  |  | } | 
| 64 |  |  |  |  |  |  |  | 
| 65 |  |  |  |  |  |  | =head2 next_available | 
| 66 |  |  |  |  |  |  |  | 
| 67 |  |  |  |  |  |  | Returns zero if there are items available, and | 
| 68 |  |  |  |  |  |  | -1 if there aren't. | 
| 69 |  |  |  |  |  |  |  | 
| 70 |  |  |  |  |  |  | =cut | 
| 71 |  |  |  |  |  |  |  | 
| 72 |  |  |  |  |  |  | sub next_available { | 
| 73 | 1674 |  |  | 1674 | 1 | 2271 | my $self = shift; | 
| 74 |  |  |  |  |  |  |  | 
| 75 | 1674 | 100 |  |  |  | 1782 | if ( 0 < @{$self->{ available_items }} ) { | 
|  | 1674 |  |  |  |  | 4435 |  | 
| 76 | 1208 |  |  |  |  | 3221 | return 0; | 
| 77 |  |  |  |  |  |  | } | 
| 78 | 466 |  |  |  |  | 1192 | return 1; | 
| 79 |  |  |  |  |  |  | } | 
| 80 |  |  |  |  |  |  |  | 
| 81 |  |  |  |  |  |  | 1; | 
| 82 |  |  |  |  |  |  |  | 
| 83 |  |  |  |  |  |  | __END__ |