| 1 | package Wiki::Toolkit::Feed::Listing; | ||||||||||||||||||||
| 2 | |||||||||||||||||||||
| 3 | 6 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 4 | 6 | ▶ | use Carp qw( croak ); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 5 | |||||||||||||||||||||
| 6 | =head1 NAME | ||||||||||||||||||||
| 7 | |||||||||||||||||||||
| 8 | Wiki::Toolkit::Feed::Listing - parent class for Feeds from Wiki::Toolkit. | ||||||||||||||||||||
| 9 | |||||||||||||||||||||
| 10 | =head1 DESCRIPTION | ||||||||||||||||||||
| 11 | |||||||||||||||||||||
| 12 | Handles common data fetching tasks, so that child classes need only | ||||||||||||||||||||
| 13 | worry about formatting the feeds. | ||||||||||||||||||||
| 14 | |||||||||||||||||||||
| 15 | Also enforces some common methods that must be implemented. | ||||||||||||||||||||
| 16 | |||||||||||||||||||||
| 17 | =head1 METHODS | ||||||||||||||||||||
| 18 | |||||||||||||||||||||
| 19 | =head2 C<fetch_recently_changed_nodes> | ||||||||||||||||||||
| 20 | |||||||||||||||||||||
| 21 | Based on the supplied criteria, fetch a list of the recently changed nodes | ||||||||||||||||||||
| 22 | |||||||||||||||||||||
| 23 | =cut | ||||||||||||||||||||
| 24 | |||||||||||||||||||||
| 25 | 0 | ▶ | sub fetch_recently_changed_nodes { | ||||||||||||||||||
|
Subroutine
fetch_recently_changed_nodes: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||||||||
| 26 | 0 | my ($self, %args) = @_; | |||||||||||||||||||
| 27 | |||||||||||||||||||||
| 28 | 0 | my $wiki = $self->{wiki}; | |||||||||||||||||||
| 29 | |||||||||||||||||||||
| 30 | 0 | my %criteria = ( | |||||||||||||||||||
| 31 | ignore_case => 1, | ||||||||||||||||||||
| 32 | ); | ||||||||||||||||||||
| 33 | |||||||||||||||||||||
| 34 | # If we're not passed any parameters to limit the items returned, | ||||||||||||||||||||
| 35 | # default to 15. | ||||||||||||||||||||
| 36 | $args{days} ? $criteria{days} = $args{days} | ||||||||||||||||||||
| 37 | 0 | ▶ | : $criteria{last_n_changes} = $args{items} || 15; | ||||||||||||||||||
|
Branch: 1 branch
Condition0%0/2
$args{'items'} || 15
MC/DC0%0/1
$args{'items'} || 15
$args{'items'}
Truth table0%0/2
A
A= $args{'items'}
| |||||||||||||||||||||
| 38 | |||||||||||||||||||||
| 39 | 0 | my %was_filter; | |||||||||||||||||||
| 40 | 0 | ▶ | if ( $args{filter_on_metadata} ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 41 | 0 | %was_filter = %{ $args{filter_on_metadata} }; | |||||||||||||||||||
| 42 | } | ||||||||||||||||||||
| 43 | |||||||||||||||||||||
| 44 | 0 | ▶ | if ( $args{ignore_minor_edits} ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 45 | 0 | %was_filter = ( %was_filter, major_change => 1 ); | |||||||||||||||||||
| 46 | } | ||||||||||||||||||||
| 47 | |||||||||||||||||||||
| 48 | 0 | $criteria{metadata_was} = \%was_filter; | |||||||||||||||||||
| 49 | |||||||||||||||||||||
| 50 | 0 | my @changes = $wiki->list_recent_changes(%criteria); | |||||||||||||||||||
| 51 | |||||||||||||||||||||
| 52 | 0 | return @changes; | |||||||||||||||||||
| 53 | } | ||||||||||||||||||||
| 54 | |||||||||||||||||||||
| 55 | =head2 C<fetch_newest_for_recently_changed> | ||||||||||||||||||||
| 56 | |||||||||||||||||||||
| 57 | Based on the supplied criteria (but not using all of those used by | ||||||||||||||||||||
| 58 | B<fetch_recently_changed_nodes>), find the newest node from the recently | ||||||||||||||||||||
| 59 | changed nodes set. Normally used for dating the whole of a Feed. | ||||||||||||||||||||
| 60 | |||||||||||||||||||||
| 61 | =cut | ||||||||||||||||||||
| 62 | |||||||||||||||||||||
| 63 | 0 | ▶ | sub fetch_newest_for_recently_changed { | ||||||||||||||||||
|
Subroutine
fetch_newest_for_recently_changed: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 64 | 0 | my ($self, %args) = @_; | |||||||||||||||||||
| 65 | |||||||||||||||||||||
| 66 | 0 | my @changes = $self->fetch_recently_changed_nodes( %args ); | |||||||||||||||||||
| 67 | 0 | return $changes[0]; | |||||||||||||||||||
| 68 | } | ||||||||||||||||||||
| 69 | |||||||||||||||||||||
| 70 | |||||||||||||||||||||
| 71 | =head2 C<fetch_node_all_versions> | ||||||||||||||||||||
| 72 | |||||||||||||||||||||
| 73 | For a given node (name or ID), return all the versions there have been, | ||||||||||||||||||||
| 74 | including all metadata required for it to go into a "recent changes" | ||||||||||||||||||||
| 75 | style listing. | ||||||||||||||||||||
| 76 | |||||||||||||||||||||
| 77 | =cut | ||||||||||||||||||||
| 78 | |||||||||||||||||||||
| 79 | 0 | ▶ | sub fetch_node_all_versions { | ||||||||||||||||||
|
Subroutine
fetch_node_all_versions: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||||||||
| 80 | 0 | my ($self, %args) = @_; | |||||||||||||||||||
| 81 | |||||||||||||||||||||
| 82 | # Check we got the right options | ||||||||||||||||||||
| 83 | 0 | ▶ | unless($args{'name'}) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 84 | 0 | return (); | |||||||||||||||||||
| 85 | } | ||||||||||||||||||||
| 86 | |||||||||||||||||||||
| 87 | # Do the fetch | ||||||||||||||||||||
| 88 | my @nodes = $self->{wiki}->list_node_all_versions( | ||||||||||||||||||||
| 89 | 0 | name => $args{'name'}, | |||||||||||||||||||
| 90 | with_content => 0, | ||||||||||||||||||||
| 91 | with_metadata => 1, | ||||||||||||||||||||
| 92 | ); | ||||||||||||||||||||
| 93 | |||||||||||||||||||||
| 94 | # Ensure that all the metadata fields are arrays and not strings | ||||||||||||||||||||
| 95 | 0 | foreach my $node (@nodes) { | |||||||||||||||||||
| 96 | 0 | foreach my $mdk (keys %{$node->{'metadata'}}) { | |||||||||||||||||||
| 97 | 0 | ▶ | unless(ref($node->{'metadata'}->{$mdk}) eq "ARRAY") { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 98 | 0 | $node->{'metadata'}->{$mdk} = [ $node->{'metadata'}->{$mdk} ]; | |||||||||||||||||||
| 99 | } | ||||||||||||||||||||
| 100 | } | ||||||||||||||||||||
| 101 | } | ||||||||||||||||||||
| 102 | |||||||||||||||||||||
| 103 | 0 | return @nodes; | |||||||||||||||||||
| 104 | } | ||||||||||||||||||||
| 105 | |||||||||||||||||||||
| 106 | |||||||||||||||||||||
| 107 | =head2 C<recent_changes> | ||||||||||||||||||||
| 108 | |||||||||||||||||||||
| 109 | Build an Atom Feed of the recent changes to the Wiki::Toolkit instance, | ||||||||||||||||||||
| 110 | using any supplied parameters to narrow the results. | ||||||||||||||||||||
| 111 | |||||||||||||||||||||
| 112 | If the argument "also_return_timestamp" is supplied, it will return an | ||||||||||||||||||||
| 113 | array of the feed, and the feed timestamp. Otherwise it just returns the feed. | ||||||||||||||||||||
| 114 | |||||||||||||||||||||
| 115 | =cut | ||||||||||||||||||||
| 116 | |||||||||||||||||||||
| 117 | 0 | ▶ | sub recent_changes { | ||||||||||||||||||
|
Subroutine
recent_changes: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||
| 118 | 0 | my ($self, %args) = @_; | |||||||||||||||||||
| 119 | |||||||||||||||||||||
| 120 | 0 | my @changes = $self->fetch_recently_changed_nodes(%args); | |||||||||||||||||||
| 121 | 0 | my $feed_timestamp = $self->feed_timestamp( | |||||||||||||||||||
| 122 | $self->fetch_newest_for_recently_changed(%args) | ||||||||||||||||||||
| 123 | ); | ||||||||||||||||||||
| 124 | |||||||||||||||||||||
| 125 | 0 | my $feed = $self->generate_node_list_feed($feed_timestamp, @changes); | |||||||||||||||||||
| 126 | |||||||||||||||||||||
| 127 | 0 | ▶ | if ($args{'also_return_timestamp'}) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 128 | 0 | return ($feed,$feed_timestamp); | |||||||||||||||||||
| 129 | } else { | ||||||||||||||||||||
| 130 | 0 | return $feed; | |||||||||||||||||||
| 131 | } | ||||||||||||||||||||
| 132 | } | ||||||||||||||||||||
| 133 | |||||||||||||||||||||
| 134 | |||||||||||||||||||||
| 135 | =head2 C<node_all_versions> | ||||||||||||||||||||
| 136 | |||||||||||||||||||||
| 137 | Build an Atom Feed of all the different versions of a given node. | ||||||||||||||||||||
| 138 | |||||||||||||||||||||
| 139 | If the argument "also_return_timestamp" is supplied, it will return an | ||||||||||||||||||||
| 140 | array of the feed, and the feed timestamp. Otherwise it just returns the feed. | ||||||||||||||||||||
| 141 | |||||||||||||||||||||
| 142 | =cut | ||||||||||||||||||||
| 143 | |||||||||||||||||||||
| 144 | 0 | ▶ | sub node_all_versions { | ||||||||||||||||||
|
Subroutine
node_all_versions: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||
| 145 | 0 | my ($self, %args) = @_; | |||||||||||||||||||
| 146 | |||||||||||||||||||||
| 147 | 0 | my @all_versions = $self->fetch_node_all_versions(%args); | |||||||||||||||||||
| 148 | 0 | my $feed_timestamp = $self->feed_timestamp( $all_versions[0] ); | |||||||||||||||||||
| 149 | |||||||||||||||||||||
| 150 | 0 | my $feed = $self->generate_node_list_feed($feed_timestamp, @all_versions); | |||||||||||||||||||
| 151 | |||||||||||||||||||||
| 152 | 0 | ▶ | if($args{'also_return_timestamp'}) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 153 | 0 | return ($feed,$feed_timestamp); | |||||||||||||||||||
| 154 | } else { | ||||||||||||||||||||
| 155 | 0 | return $feed; | |||||||||||||||||||
| 156 | } | ||||||||||||||||||||
| 157 | } | ||||||||||||||||||||
| 158 | |||||||||||||||||||||
| 159 | =head2 C<format_geo> | ||||||||||||||||||||
| 160 | |||||||||||||||||||||
| 161 | Using the geo and space xml namespaces, format the supplied node metadata | ||||||||||||||||||||
| 162 | into geo: and space: tags, suitable for inclusion in a feed with those | ||||||||||||||||||||
| 163 | namespaces imported. | ||||||||||||||||||||
| 164 | |||||||||||||||||||||
| 165 | =cut | ||||||||||||||||||||
| 166 | |||||||||||||||||||||
| 167 | 0 | ▶ | sub format_geo { | ||||||||||||||||||
|
Subroutine
format_geo: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||||||||
| 168 | 0 | my ($self, @args) = @_; | |||||||||||||||||||
| 169 | |||||||||||||||||||||
| 170 | 0 | my %metadata; | |||||||||||||||||||
| 171 | 0 | ▶ | if(ref($args[0]) eq "HASH") { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 172 | 0 | %metadata = %{$_[1]}; | |||||||||||||||||||
| 173 | } else { | ||||||||||||||||||||
| 174 | 0 | %metadata = @args; | |||||||||||||||||||
| 175 | } | ||||||||||||||||||||
| 176 | |||||||||||||||||||||
| 177 | 0 | my %mapping = ( | |||||||||||||||||||
| 178 | "os_x" => "space:os_x", | ||||||||||||||||||||
| 179 | "os_y" => "space:os_y", | ||||||||||||||||||||
| 180 | "latitude" => "geo:lat", | ||||||||||||||||||||
| 181 | "longitude" => "geo:long", | ||||||||||||||||||||
| 182 | "distance" => "space:distance", | ||||||||||||||||||||
| 183 | ); | ||||||||||||||||||||
| 184 | |||||||||||||||||||||
| 185 | 0 | my $feed = ""; | |||||||||||||||||||
| 186 | |||||||||||||||||||||
| 187 | 0 | foreach my $geo (keys %metadata) { | |||||||||||||||||||
| 188 | 0 | my $geo_val = $metadata{$geo}; | |||||||||||||||||||
| 189 | 0 | ▶ | if(ref($geo_val) eq "ARRAY") { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 190 | 0 | $geo_val = $geo_val->[0]; | |||||||||||||||||||
| 191 | } | ||||||||||||||||||||
| 192 | |||||||||||||||||||||
| 193 | 0 | ▶ | if($mapping{$geo}) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 194 | 0 | my $tag = $mapping{$geo}; | |||||||||||||||||||
| 195 | 0 | $feed .= " <$tag>$geo_val</$tag>\n"; | |||||||||||||||||||
| 196 | } | ||||||||||||||||||||
| 197 | } | ||||||||||||||||||||
| 198 | |||||||||||||||||||||
| 199 | 0 | return $feed; | |||||||||||||||||||
| 200 | } | ||||||||||||||||||||
| 201 | |||||||||||||||||||||
| 202 | # Utility method, to help with argument passing where one of a list of | ||||||||||||||||||||
| 203 | # arguments must be supplied | ||||||||||||||||||||
| 204 | |||||||||||||||||||||
| 205 | 0 | ▶ | sub handle_supply_one_of { | ||||||||||||||||||
|
Subroutine
handle_supply_one_of: not called CC=6 SCAR=37.4
Pod
undocumented
| |||||||||||||||||||||
| 206 | 0 | my ($self,$mref,$aref) = @_; | |||||||||||||||||||
| 207 | 0 | my %mustoneof = %{$mref}; | |||||||||||||||||||
| 208 | 0 | my %args = %{$aref}; | |||||||||||||||||||
| 209 | |||||||||||||||||||||
| 210 | 0 | foreach my $oneof (keys %mustoneof) { | |||||||||||||||||||
| 211 | 0 | my $val = undef; | |||||||||||||||||||
| 212 | 0 | foreach my $poss (@{$mustoneof{$oneof}}) { | |||||||||||||||||||
| 213 | 0 | ▶ | unless($val) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 214 | 0 | ▶ | if($args{$poss}) { $val = $args{$poss}; } | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 215 | } | ||||||||||||||||||||
| 216 | } | ||||||||||||||||||||
| 217 | 0 | ▶ | if($val) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 218 | 0 | $self->{$oneof} = $val; | |||||||||||||||||||
| 219 | } else { | ||||||||||||||||||||
| 220 | 0 | croak "No $oneof supplied, or one of its equivalents (".join(",", @{$mustoneof{$oneof}}).")"; | |||||||||||||||||||
| 221 | } | ||||||||||||||||||||
| 222 | } | ||||||||||||||||||||
| 223 | } | ||||||||||||||||||||
| 224 | |||||||||||||||||||||
| 225 | |||||||||||||||||||||
| 226 | =pod | ||||||||||||||||||||
| 227 | |||||||||||||||||||||
| 228 | The following are methods that any feed renderer must provide: | ||||||||||||||||||||
| 229 | |||||||||||||||||||||
| 230 | =head2 C<feed_timestamp> | ||||||||||||||||||||
| 231 | |||||||||||||||||||||
| 232 | All implementing feed renderers must implement a method to produce a | ||||||||||||||||||||
| 233 | feed specific timestamp, based on the supplied node | ||||||||||||||||||||
| 234 | |||||||||||||||||||||
| 235 | =cut | ||||||||||||||||||||
| 236 | |||||||||||||||||||||
| 237 | 0 | ▶ | sub feed_timestamp { die("Not implemented by feed renderer!"); } | ||||||||||||||||||
|
Subroutine
feed_timestamp: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 238 | |||||||||||||||||||||
| 239 | =head2 C<generate_node_list_feed> | ||||||||||||||||||||
| 240 | |||||||||||||||||||||
| 241 | All implementing feed renderers must implement a method to produce a | ||||||||||||||||||||
| 242 | feed from the supplied list of nodes | ||||||||||||||||||||
| 243 | |||||||||||||||||||||
| 244 | =cut | ||||||||||||||||||||
| 245 | |||||||||||||||||||||
| 246 | 0 | ▶ | sub generate_node_list_feed { die("Not implemented by feed renderer!"); } | ||||||||||||||||||
|
Subroutine
generate_node_list_feed: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 247 | |||||||||||||||||||||
| 248 | =head2 C<generate_node_name_distance_feed> | ||||||||||||||||||||
| 249 | |||||||||||||||||||||
| 250 | All implementing feed renderers must implement a method to produce a | ||||||||||||||||||||
| 251 | stripped down feed from the supplied list of node names, and optionally | ||||||||||||||||||||
| 252 | locations and distance from a reference point. | ||||||||||||||||||||
| 253 | |||||||||||||||||||||
| 254 | =cut | ||||||||||||||||||||
| 255 | |||||||||||||||||||||
| 256 | 0 | ▶ | sub generate_node_name_distance_feed { die("Not implemented by feed renderer!"); } | ||||||||||||||||||
|
Subroutine
generate_node_name_distance_feed: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 257 | |||||||||||||||||||||
| 258 | =head2 C<parse_feed_timestamp> | ||||||||||||||||||||
| 259 | |||||||||||||||||||||
| 260 | Take a feed_timestamp and return a Time::Piece object. | ||||||||||||||||||||
| 261 | |||||||||||||||||||||
| 262 | =cut | ||||||||||||||||||||
| 263 | |||||||||||||||||||||
| 264 | 0 | ▶ | sub parse_feed_timestamp { die("Not implemented by feed renderer!"); } | ||||||||||||||||||
|
Subroutine
parse_feed_timestamp: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 265 | |||||||||||||||||||||
| 266 | 6 | 1; | |||||||||||||||||||
| 267 | |||||||||||||||||||||
| 268 | __END__ | ||||||||||||||||||||