File: YAMLConfig.pm

package info (click to toggle)
libperlanet-perl 2.2.1-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 444 kB
  • sloc: xml: 1,177; perl: 757; sh: 6; makefile: 5
file content (113 lines) | stat: -rw-r--r-- 2,275 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
package Perlanet::Trait::YAMLConfig;

use 5.10.0;
use strict;
use warnings;

use Moose::Role;
use namespace::autoclean;

=head1 NAME

Perlanet::Trait::YAMLConfig - configure Perlanet through a YAML configuration
file

=head1 SYNOPSIS

   package MyPerlanet;
   extends 'Perlanet';
   with 'Perlanet::Traits::YAMLConfig';

   my $perlanet = MyPerlanet->new_with_config(
     configfile => 'whatever.yml'
   );

   $perlanet->run;

=head1 DESCRIPTION

Allows you to move the configuration of Perlanet to an external YAML
configuration file.

=head2 Example Configuration File

  title: planet test
  description: A Test Planet
  url: http://planet.example.com/
  author:
    name: Dave Cross
    email: dave@dave.org.uk
  entries: 20
  opml: opml.xml
  page:
    file: index.html
    template: index.tt
  feed:
    file: atom.xml
    format: Atom
  cache_dir: /tmp/feeds
  feeds:
    - url: http://blog.dave.org.uk/atom.xml
      title: Dave's Blog
      web: http://blog.dave.org.uk/
    - url: http://use.perl.org/~davorg/journal/rss
      title: Dave's use.perl Journal
      web: http://use.perl.org/~davorg/journal/
    - url: http://www.oreillynet.com/pub/feed/31?au=2607
      title: Dave on O'Reillynet
      web: http://www.oreillynet.com/pub/au/2607

=head1 METHODS

=head2 get_config_from_file

Extracts the configuration from a YAML file

=cut

with 'MooseX::ConfigFromFile', 'Perlanet::Role::Config';

use Carp qw( carp croak );
use YAML qw( LoadFile );

sub get_config_from_file {
  my $class = shift;
  return $class->get_config(config_file => $_[0]);
}

=head2 read_config

Actually reads the YAML.

=cut

sub read_config {
  my $class = shift;
  my (%params) = @_;

  my $file = $params{config_file}
    // croak "No config file passed to read_config().";

  open my $cfg_file, '<:encoding(UTF-8)', $file
    or croak "Cannot open file $file: $!";

  my $cfg = LoadFile($cfg_file);

  return $cfg;
}

=head1 AUTHOR

Oliver Charles, <oliver.g.charles@googlemail.com>

=head1 COPYRIGHT AND LICENSE

Copyright (c) 2010 by Magnum Solutions Ltd.

This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself, either Perl version 5.10.0 or,
at your option, any later version of Perl 5 you may have available.

=cut

1;