| 1 | package OurCal::Provider::Multi; | ||||||||||
| 2 | |||||||||||
| 3 | 2 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 2 | ▶ | use OurCal::Provider; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | |||||||||||
| 6 | |||||||||||
| 7 | =head1 NAME | ||||||||||
| 8 | |||||||||||
| 9 | OurCal::Provider::Multi - aggregate multiple providers | ||||||||||
| 10 | |||||||||||
| 11 | =head1 SYNOPSIS | ||||||||||
| 12 | |||||||||||
| 13 | [a_multi_provider] | ||||||||||
| 14 | providers = something another | ||||||||||
| 15 | type = multi | ||||||||||
| 16 | |||||||||||
| 17 | =head1 CONFIG OPTIONS | ||||||||||
| 18 | |||||||||||
| 19 | =over 3 | ||||||||||
| 20 | |||||||||||
| 21 | =item providers | ||||||||||
| 22 | |||||||||||
| 23 | A space separated list of other provider names | ||||||||||
| 24 | |||||||||||
| 25 | =back | ||||||||||
| 26 | |||||||||||
| 27 | =head1 METHODS | ||||||||||
| 28 | |||||||||||
| 29 | =cut | ||||||||||
| 30 | |||||||||||
| 31 | =head2 new <param[s]> | ||||||||||
| 32 | |||||||||||
| 33 | Requires an C<OurCal::Config> object as config param and a name param. | ||||||||||
| 34 | |||||||||||
| 35 | =cut | ||||||||||
| 36 | |||||||||||
| 37 | 0 | ▶ | sub new { | ||||||||
|
Subroutine
new: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||
| 38 | 0 | my $class = shift; | |||||||||
| 39 | 0 | my %what = @_; | |||||||||
| 40 | |||||||||||
| 41 | # get all the names of of our providers | ||||||||||
| 42 | 0 | my $conf = $what{config}->config($what{name}); | |||||||||
| 43 | 0 | my $providers = $conf->{providers}; | |||||||||
| 44 | 0 | my $default = 0; | |||||||||
| 45 | 0 | foreach my $provider (split ' ', $providers) { | |||||||||
| 46 | 0 | $what{_providers}->{$provider} = OurCal::Provider->load_provider($provider, $what{config}); | |||||||||
| 47 | 0 | ▶ | $default = 1 if $provider eq 'default'; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 48 | } | ||||||||||
| 49 | 0 | return bless \%what, $class; | |||||||||
| 50 | } | ||||||||||
| 51 | |||||||||||
| 52 | 0 | ▶ | sub todos { | ||||||||
|
Subroutine
todos: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 53 | 0 | my $self = shift; | |||||||||
| 54 | 0 | return $self->_gather('todos'); | |||||||||
| 55 | } | ||||||||||
| 56 | |||||||||||
| 57 | 0 | ▶ | sub providers { | ||||||||
|
Subroutine
providers: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 58 | 0 | my $self = shift; | |||||||||
| 59 | 0 | return values %{$self->{_providers}}; | |||||||||
| 60 | } | ||||||||||
| 61 | |||||||||||
| 62 | 0 | ▶ | sub has_events { | ||||||||
|
Subroutine
has_events: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||
| 63 | 0 | my $self = shift; | |||||||||
| 64 | 0 | my %opts = @_; | |||||||||
| 65 | 0 | foreach my $provider ($self->providers) { | |||||||||
| 66 | 0 | ▶ | return 1 if $provider->has_events(%opts); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 67 | } | ||||||||||
| 68 | 0 | return 0; | |||||||||
| 69 | } | ||||||||||
| 70 | |||||||||||
| 71 | 0 | ▶ | sub events { | ||||||||
|
Subroutine
events: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||
| 72 | 0 | my $self = shift; | |||||||||
| 73 | 0 | my %opts = @_; | |||||||||
| 74 | 0 | my @events = sort { $b->date cmp $a->date } $self->_gather('events', %opts); | |||||||||
| 75 | 0 | ▶ | @events = splice @events, 0, $opts{limit} if defined $opts{limit}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 76 | 0 | return @events; | |||||||||
| 77 | } | ||||||||||
| 78 | |||||||||||
| 79 | 0 | ▶ | sub users { | ||||||||
|
Subroutine
users: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 80 | 0 | my $self = shift; | |||||||||
| 81 | 0 | return $self->_gather('users', @_); | |||||||||
| 82 | } | ||||||||||
| 83 | |||||||||||
| 84 | 0 | ▶ | sub _gather { | ||||||||
|
Subroutine
_gather: not called CC=2 SCAR=17.9
| |||||||||||
| 85 | 0 | my $self = shift; | |||||||||
| 86 | 0 | my $sub = shift; | |||||||||
| 87 | 0 | my %opts = @_; | |||||||||
| 88 | |||||||||||
| 89 | 0 | my @vals; | |||||||||
| 90 | 0 | foreach my $provider ($self->providers) { | |||||||||
| 91 | 0 | push @vals, $provider->$sub(%opts); | |||||||||
| 92 | } | ||||||||||
| 93 | 0 | return @vals; | |||||||||
| 94 | |||||||||||
| 95 | } | ||||||||||
| 96 | |||||||||||
| 97 | 0 | ▶ | sub save_todo { | ||||||||
|
Subroutine
save_todo: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 98 | 0 | my $self = shift; | |||||||||
| 99 | 0 | return $self->_do_default('save_todo', @_); | |||||||||
| 100 | } | ||||||||||
| 101 | |||||||||||
| 102 | 0 | ▶ | sub del_todo { | ||||||||
|
Subroutine
del_todo: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 103 | 0 | my $self = shift; | |||||||||
| 104 | 0 | return $self->_do_default('del_todo', @_); | |||||||||
| 105 | } | ||||||||||
| 106 | |||||||||||
| 107 | |||||||||||
| 108 | 0 | ▶ | sub save_event { | ||||||||
|
Subroutine
save_event: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 109 | 0 | my $self = shift; | |||||||||
| 110 | 0 | return $self->_do_default('save_event', @_); | |||||||||
| 111 | } | ||||||||||
| 112 | |||||||||||
| 113 | 0 | ▶ | sub del_event { | ||||||||
|
Subroutine
del_event: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 114 | 0 | my $self = shift; | |||||||||
| 115 | 0 | return $self->_do_default('del_event', @_); | |||||||||
| 116 | } | ||||||||||
| 117 | |||||||||||
| 118 | 0 | ▶ | sub _do_default { | ||||||||
|
Subroutine
_do_default: not called CC=2 SCAR=17.9
| |||||||||||
| 119 | 0 | my $self = shift; | |||||||||
| 120 | 0 | my $sub = shift; | |||||||||
| 121 | 0 | my $thing = shift; | |||||||||
| 122 | die "You must specify at least one provider named 'default' if you want to save\n" | ||||||||||
| 123 | 0 | ▶ | unless $self->{_providers}->{default}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 124 | 0 | $self->{_providers}->{default}->$sub($thing); | |||||||||
| 125 | } | ||||||||||
| 126 | |||||||||||
| 127 | =head2 todos | ||||||||||
| 128 | |||||||||||
| 129 | Returns all the todos on the system. | ||||||||||
| 130 | |||||||||||
| 131 | =head2 has_events <param[s]> | ||||||||||
| 132 | |||||||||||
| 133 | Returns whether there are events given the params. | ||||||||||
| 134 | |||||||||||
| 135 | =head2 events <param[s]> | ||||||||||
| 136 | |||||||||||
| 137 | Returns all the events for the given params. | ||||||||||
| 138 | |||||||||||
| 139 | =head2 users | ||||||||||
| 140 | |||||||||||
| 141 | Returns the name of all the users on the system. | ||||||||||
| 142 | |||||||||||
| 143 | =head2 save_todo <OurCal::Todo> | ||||||||||
| 144 | |||||||||||
| 145 | Save a todo. | ||||||||||
| 146 | |||||||||||
| 147 | =head2 del_todo <OurCal::Todo> | ||||||||||
| 148 | |||||||||||
| 149 | Delete a todo. | ||||||||||
| 150 | |||||||||||
| 151 | |||||||||||
| 152 | =head2 save_event <OurCal::Event> | ||||||||||
| 153 | |||||||||||
| 154 | Save an event. | ||||||||||
| 155 | |||||||||||
| 156 | =head2 del_event <OurCal::Event> | ||||||||||
| 157 | |||||||||||
| 158 | Delete an event.. | ||||||||||
| 159 | |||||||||||
| 160 | =cut | ||||||||||
| 161 | |||||||||||
| 162 | |||||||||||
| 163 | |||||||||||
| 164 | 2 | 1; | |||||||||
| 165 | |||||||||||