line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Perlanet::Trait::YAMLConfig; |
2
|
|
|
|
|
|
|
|
3
|
6
|
|
|
6
|
|
3834
|
use strict; |
|
6
|
|
|
|
|
18
|
|
|
6
|
|
|
|
|
199
|
|
4
|
6
|
|
|
6
|
|
39
|
use warnings; |
|
6
|
|
|
|
|
17
|
|
|
6
|
|
|
|
|
181
|
|
5
|
|
|
|
|
|
|
|
6
|
6
|
|
|
6
|
|
37
|
use Moose::Role; |
|
6
|
|
|
|
|
17
|
|
|
6
|
|
|
|
|
54
|
|
7
|
6
|
|
|
6
|
|
37952
|
use namespace::autoclean; |
|
6
|
|
|
|
|
18
|
|
|
6
|
|
|
|
|
71
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
=head1 NAME |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
Perlanet::Trait::YAMLConfig - configure Perlanet through a YAML configuration |
12
|
|
|
|
|
|
|
file |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
=head1 SYNOPSIS |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
package MyPerlanet; |
17
|
|
|
|
|
|
|
extends 'Perlanet'; |
18
|
|
|
|
|
|
|
with 'Perlanet::Traits::YAMLConfig'; |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
my $perlanet = MyPerlanet->new_with_config( |
21
|
|
|
|
|
|
|
configfile => 'whatever.yml' |
22
|
|
|
|
|
|
|
); |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
$perlanet->run; |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
=head1 DESCRIPTION |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
Allows you to move the configuration of Perlanet to an external YAML |
29
|
|
|
|
|
|
|
configuration file. |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
=head2 Example Configuration File |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
title: planet test |
34
|
|
|
|
|
|
|
description: A Test Planet |
35
|
|
|
|
|
|
|
url: http://planet.example.com/ |
36
|
|
|
|
|
|
|
author: |
37
|
|
|
|
|
|
|
name: Dave Cross |
38
|
|
|
|
|
|
|
email: dave@dave.org.uk |
39
|
|
|
|
|
|
|
entries: 20 |
40
|
|
|
|
|
|
|
opml: opml.xml |
41
|
|
|
|
|
|
|
page: |
42
|
|
|
|
|
|
|
file: index.html |
43
|
|
|
|
|
|
|
template: index.tt |
44
|
|
|
|
|
|
|
feed: |
45
|
|
|
|
|
|
|
file: atom.xml |
46
|
|
|
|
|
|
|
format: Atom |
47
|
|
|
|
|
|
|
cache_dir: /tmp/feeds |
48
|
|
|
|
|
|
|
feeds: |
49
|
|
|
|
|
|
|
- url: http://blog.dave.org.uk/atom.xml |
50
|
|
|
|
|
|
|
title: Dave's Blog |
51
|
|
|
|
|
|
|
web: http://blog.dave.org.uk/ |
52
|
|
|
|
|
|
|
- url: http://use.perl.org/~davorg/journal/rss |
53
|
|
|
|
|
|
|
title: Dave's use.perl Journal |
54
|
|
|
|
|
|
|
web: http://use.perl.org/~davorg/journal/ |
55
|
|
|
|
|
|
|
- url: http://www.oreillynet.com/pub/feed/31?au=2607 |
56
|
|
|
|
|
|
|
title: Dave on O'Reillynet |
57
|
|
|
|
|
|
|
web: http://www.oreillynet.com/pub/au/2607 |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
=head1 METHODS |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
=head2 THIRTY_DAYS |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
The default length of caching, if caching options are present in the |
64
|
|
|
|
|
|
|
configuration |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
=head2 get_config_from_file |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
Extracts the configuration from a YAML file |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
=cut |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
with 'MooseX::ConfigFromFile'; |
73
|
|
|
|
|
|
|
|
74
|
6
|
|
|
6
|
|
716
|
use Carp qw( carp croak ); |
|
6
|
|
|
|
|
18
|
|
|
6
|
|
|
|
|
486
|
|
75
|
6
|
|
|
6
|
|
91
|
use YAML qw( LoadFile ); |
|
6
|
|
|
|
|
19
|
|
|
6
|
|
|
|
|
465
|
|
76
|
|
|
|
|
|
|
|
77
|
6
|
|
|
6
|
|
43
|
use constant THIRTY_DAYS => 30 * 24 * 60 * 60; |
|
6
|
|
|
|
|
17
|
|
|
6
|
|
|
|
|
2103
|
|
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
sub get_config_from_file { |
80
|
5
|
|
|
5
|
1
|
52086
|
my ($self, $file) = @_; |
81
|
|
|
|
|
|
|
|
82
|
5
|
100
|
|
|
|
478
|
open my $cfg_file, '<:utf8', $file |
83
|
|
|
|
|
|
|
or croak "Cannot open file $file: $!"; |
84
|
|
|
|
|
|
|
|
85
|
4
|
|
|
|
|
43
|
my $cfg = LoadFile($cfg_file); |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
$cfg->{feeds} = [ map { |
88
|
5
|
|
|
|
|
236
|
Perlanet::Feed->new($_) |
89
|
4
|
|
|
|
|
102399
|
} @{ $cfg->{feeds} } ]; |
|
4
|
|
|
|
|
22
|
|
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
$cfg->{max_entries} = $cfg->{entries} |
92
|
4
|
100
|
|
|
|
30
|
if $cfg->{entries}; |
93
|
|
|
|
|
|
|
|
94
|
4
|
100
|
|
|
|
64
|
if ($cfg->{cache_dir}) { |
95
|
1
|
|
|
|
|
2
|
eval { require CHI; }; |
|
1
|
|
|
|
|
7
|
|
96
|
|
|
|
|
|
|
|
97
|
1
|
50
|
|
|
|
4
|
if ($@) { |
98
|
0
|
|
|
|
|
0
|
carp "You need to install CHI to enable caching.\n"; |
99
|
0
|
|
|
|
|
0
|
carp "Caching disabled for this run.\n"; |
100
|
0
|
|
|
|
|
0
|
delete $cfg->{cache_dir}; |
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
$cfg->{cache_dir} |
105
|
|
|
|
|
|
|
and $cfg->{cache} = CHI->new( |
106
|
|
|
|
|
|
|
driver => 'File', |
107
|
|
|
|
|
|
|
root_dir => delete $cfg->{cache_dir}, |
108
|
4
|
100
|
|
|
|
41
|
expires_in => THIRTY_DAYS, |
109
|
|
|
|
|
|
|
); |
110
|
|
|
|
|
|
|
|
111
|
4
|
|
|
|
|
101301
|
return $cfg; |
112
|
|
|
|
|
|
|
} |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
=head1 AUTHOR |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
Oliver Charles, <oliver.g.charles@googlemail.com> |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
Copyright (c) 2010 by Magnum Solutions Ltd. |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or modify |
123
|
|
|
|
|
|
|
it under the same terms as Perl itself, either Perl version 5.10.0 or, |
124
|
|
|
|
|
|
|
at your option, any later version of Perl 5 you may have available. |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
=cut |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
1; |