blib/lib/Catalyst/Plugin/Config/YAML.pm

filter: Statementstmt 100% 9 / 9 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 3 / 3 Podpod n/a totaltotal 100% 12 / 12 CC 1 SCAR 0.0
CC
1
Cov
100%
BEGIN
1.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.0
↑ Summary
1 package Catalyst::Plugin::Config::YAML;
2  
3 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 3 ▶use UNIVERSAL 'isa';
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 use NEXT;
9 use YAML 'LoadFile';
10 use Path::Class 'file';
11  
12 our $VERSION = '0.04';
13  
14 =head1 NAME
15  
16 Catalyst::Plugin::Config::YAML - Configure your Catalyst application via an
17 external YAML file
18  
19 =head1 SYNOPSIS
20  
21 use Catalyst 'Config::YAML';
22
23 __PACKAGE__->config('config_file' => 'config.yml');
24  
25 =head1 DESCRIPTION
26  
27 This Catalyst plugin enables you to configure your Catalyst application with an
28 external YAML file instead of somewhere in your application code.
29  
30 This is useful for example if you want to quickly change the configuration for
31 different deployment environments (like development, testing or production)
32 without changing your code.
33  
34 The configuration file is assumed to be in your application home. Its name can
35 be specified with the config parameter C<config_file> (default is
36 F<config.yml>).
37  
38 The config parameter C<config_file> can also be an array of locations (relative
39 or absolute), each found file will be loaded in order.
40  
41 =head2 EXTENDED METHODS
42  
43 =over
44  
45 =item setup
46  
47 =cut
48  
49 sub setup {
50 my $c = shift;
51 my @config_files;
52 if ( defined $c->config->{'config_file'} && ref $c->config->{'config_file'} eq 'ARRAY' ) {
53 @config_files = @{$c->config->{'config_file'}};
54 } else {
55 my $config_file = $c->config->{'config_file'} || 'config.yml';
56 push @config_files, $config_file;
57 }
58 foreach my $config_file ( @config_files ) {
59 $config_file = file($c->config->{'home'}, $config_file) unless file($config_file)->is_absolute;
60 next unless -e $config_file;
61 my $options = LoadFile($config_file);
62 $c->config($options);
63 }
64 $c->NEXT::setup;
65 }
66  
67 =back
68  
69 =head1 SEE ALSO
70  
71 L<Catalyst>, L<YAML>.
72  
73 =head1 AUTHOR
74  
75 Bernhard Bauer, E<lt>bauerb@in.tum.deE<gt>
76  
77 =head1 COPYRIGHT AND LICENSE
78  
79 Copyright 2005 by Bernhard Bauer
80  
81 This library is free software; you can redistribute it and/or modify
82 it under the same terms as Perl itself.
83  
84 =cut
↑ Summary