line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package XML::Feed::Aggregator::Sort; |
2
|
|
|
|
|
|
|
BEGIN { |
3
|
1
|
|
|
1
|
|
1308
|
$XML::Feed::Aggregator::Sort::VERSION = '0.0401'; |
4
|
|
|
|
|
|
|
} |
5
|
1
|
|
|
1
|
|
906
|
use Moose::Role; |
|
1
|
|
|
|
|
663723
|
|
|
1
|
|
|
|
|
6
|
|
6
|
|
|
|
|
|
|
requires 'sort_entries'; |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
sub sort_by_date { |
9
|
0
|
|
|
0
|
1
|
|
my ($self) = @_; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
$self->sort_entries(sub { |
12
|
0
|
|
0
|
0
|
|
|
my $adt = $_[0]->issued || $_[0]->modified; |
13
|
0
|
|
0
|
|
|
|
my $bdt = $_[1]->issued || $_[1]->modified; |
14
|
0
|
|
|
|
|
|
return $adt->compare($bdt); |
15
|
0
|
|
|
|
|
|
}); |
16
|
|
|
|
|
|
|
|
17
|
0
|
|
|
|
|
|
return $self; |
18
|
|
|
|
|
|
|
} |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
sub sort_by_date_ascending { |
21
|
0
|
|
|
0
|
1
|
|
my ($self) = @_; |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
$self->sort_entries(sub { |
24
|
0
|
|
0
|
0
|
|
|
my $adt = $_[0]->issued || $_[0]->modified; |
25
|
0
|
|
0
|
|
|
|
my $bdt = $_[1]->issued || $_[1]->modified; |
26
|
0
|
|
|
|
|
|
return $bdt->compare($adt); |
27
|
0
|
|
|
|
|
|
}); |
28
|
|
|
|
|
|
|
|
29
|
0
|
|
|
|
|
|
return $self; |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub sort { |
33
|
0
|
|
|
0
|
0
|
|
my ($self, $order) = @_; |
34
|
|
|
|
|
|
|
|
35
|
0
|
|
|
|
|
|
warn "Called deprecated method ->sort"; |
36
|
|
|
|
|
|
|
|
37
|
0
|
0
|
|
|
|
|
if ($order eq 'desc') { |
38
|
0
|
|
|
|
|
|
$self->sort_by_date; |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
else { |
41
|
0
|
|
|
|
|
|
$self->sort_by_date_ascending; |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
0
|
|
|
|
|
|
return $self; |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
1; |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
=pod |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
=head1 NAME |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
XML::Feed::Aggregator::Sort |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
=head1 VERSION |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
version 0.0401 |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
=head1 SYNOPSIS |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
# builtin sort methods: |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
$aggregator->sort_by_date_ascending; |
65
|
|
|
|
|
|
|
$aggregator->sort_by_date; |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
# custom sort routine |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
$aggregator->sort_entries(sub { |
70
|
|
|
|
|
|
|
$_[0]->title cmp $_[1]->title |
71
|
|
|
|
|
|
|
}); |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
=head1 NAME |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
XML::Feed::Aggregator::Sort - Role for sorting feed entries |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
=head1 METHODS |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
=head2 sort_entries |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
Provide your own sorting routine via a CodeRef, two entries provided as arguments. |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
=head2 sort_by_date |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
Sort entries with date in descending order. |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
=head2 sort_by_date_ascending |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
Sort entries with date in ascending order. |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
=head1 SEE ALSO |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
L<XML::Feed::Aggregator> |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
L<XML::Feed::Aggregator::Deduper> |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
=head1 AUTHOR |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
Robin Edwards <robin.ge@gmail.com> |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
This software is copyright (c) 2011 by Robin Edwards. |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
106
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
=cut |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
__END__ |
112
|
|
|
|
|
|
|
|