blib/lib/Catalyst/Plugin/ConfigLoader/Remote.pm

filter: Statementstmt 58.9% 23 / 39 Branchbran 0.0% 0 / 8 Conditioncond 0.0% 0 / 9 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 87.5% 7 / 8 Podpod 100% 1 / 1 totaltotal 43.6% 31 / 71 CC 9 SCAR 39.3
CC
9
Cov
41%
find_files
90.0
BEGIN
1.0
BEGIN
1.0
CRAP 51.1
↑ Summary
1 package Catalyst::Plugin::ConfigLoader::Remote;
2  
3 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 2 ▶use File::Fetch;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 ▶use Scalar::Util qw(blessed);
Subroutine BEGIN: called CC=1 SCAR=0.0
8 2 ▶use File::Temp qw/tempdir/;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 2 ▶use MRO::Compat;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 2 ▶use base qw/Catalyst::Plugin::ConfigLoader/;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 =head1 NAME
15  
16 Catalyst::Plugin::ConfigLoader::Remote - Load (remote) URIs into config
17  
18 =head1 VERSION
19  
20 Version 0.01
21  
22 =cut
23  
24 2 our $VERSION = '0.02';
25  
26 =head1 SYNOPSIS
27  
28 This module provides support for fetching remote configuration files over HTTP,
29 FTP or other remote methods.
30  
31 It will fetch any blessed URI object in the C<files> config entry for the
32 package via L<File::Fetch>
33  
34 package MyApp;
35  
36 use Catalyst qw/ConfigLoader::Remote/;
37  
38 use URI;
39  
40 __PACKAGE__->config(
41 'Plugin::ConfigLoader::Remote' => {
42 files => [
43 URI->new("https://secure.example.com/config/basic.yml"),
44 URI->new("https://secure.example.com/config/database.conf"),
45 ]
46 }
47 );
48  
49 =head1 METHODS
50  
51 =head2 find_files
52  
53 find_files will download each file to a temporary directory that is purged on
54 program exit. It is then passed to L<Catalyst::Plugin::ConfigLoader> for
55 actual configuration loading and processing.
56  
57 =cut
58  
59 0 ▶sub find_files {
Subroutine find_files: not called CC=9 SCAR=45.0
Pod documented
60 0 my $c = shift;
61  
62 0 my $tempdir = tempdir( CLEANUP => 1 );
63  
64 # Load up the other files that are coming in.
65 0 my @files = $c->next::method();
66  
67 0 my $config = $c->config->{'Plugin::ConfigLoader::Remote'};
68  
69 return @files unless ref $config eq 'HASH' and
70 0 ▶ ref $config->{files} eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $config eq "HASH" and ref $config->{"files"} eq "ARRAY" 0 0 0
Condition0%0/3
ref $config eq "HASH" and ref $config->{"files"} eq "ARRAY"
!ll&&!rl&&r
000
MC/DC0%0/2
ref $config eq "HASH" and ref $config->{"files"} eq "ARRAY"
ref $config eq "HASH" ref $config->{"files"} eq "ARRAY"
Truth table0%0/3
A and B
A= ref $config eq "HASH"B= ref $config->{"files"} eq "ARRAY"
ABresult
0X0
100
111
71  
72 my @incoming_files =
73 0 @{ $config->{files} };
74  
75 # replace everything in @files that is a URI object with a downloaded copy
76 0 foreach my $arg ( @incoming_files ) {
77 0 ▶ if ( blessed $arg and $arg->isa('URI') ) {
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::blessed($arg) and $arg->isa('URI')) { } 0 0 0
Condition0%0/3
builtin::blessed($arg) and $arg->isa("URI")
!ll&&!rl&&r
000
MC/DC0%0/2
builtin::blessed($arg) and $arg->isa("URI")
builtin::blessed($arg) $arg->isa("URI")
Truth table0%0/3
A and B
A= builtin::blessed($arg)B= $arg->isa("URI")
ABresult
0X0
100
111
78 # Fetch a blessed URI
79 0 my $ff = File::Fetch->new( uri => $arg->as_string );
80 0 ▶ if ( $ff ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ff) 0 0 0
81 0 my $file = $ff->fetch( to => $tempdir );
82 0 ▶ if ( $file and -f $file ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($file and -f $file) 0 0 0
Condition0%0/3
$file and -f $file
!ll&&!rl&&r
000
MC/DC0%0/2
$file and -f $file
$file -f $file
Truth table0%0/3
A and B
A= $fileB= -f $file
ABresult
0X0
100
111
83 0 push @files, $file;
84 }
85 }
86 } else {
87 0 push @files, $arg;
88 }
89 }
90  
91 0 return @files;
92 }
93  
94 =head1 AUTHOR
95  
96 J. Shirley, C<< <jshirley at gmail.com> >>
97  
98 Eden Cardim
99  
100 =head1 BUGS
101  
102 Please report any bugs or feature requests to
103 C<bug-catalyst-plugin-configloader-remote at rt.cpan.org>, or through the web interface at
104 L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Catalyst-Plugin-ConfigLoader-Remote>.
105 I will be notified, and then you'll automatically be notified of progress on
106 your bug as I make changes.
107  
108 =head1 SUPPORT
109  
110 You can find documentation for this module with the perldoc command.
111  
112 perldoc Catalyst::Plugin::ConfigLoader::Remote
113  
114 You can also look for information at:
115  
116 =over 4
117  
118 =item * AnnoCPAN: Annotated CPAN documentation
119  
120 L<http://annocpan.org/dist/Catalyst-Plugin-ConfigLoader-Remote>
121  
122 =item * CPAN Ratings
123  
124 L<http://cpanratings.perl.org/d/Catalyst-Plugin-ConfigLoader-Remote>
125  
126 =item * RT: CPAN's request tracker
127  
128 L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Catalyst-Plugin-ConfigLoader-Remote>
129  
130 =item * Search CPAN
131  
132 L<http://search.cpan.org/dist/Catalyst-Plugin-ConfigLoader-Remote>
133  
134 =back
135  
136 =head1 ACKNOWLEDGEMENTS
137  
138 =head1 COPYRIGHT & LICENSE
139  
140 Copyright 2007 J. Shirley and PictureTrail.com
141  
142 This program is free software; you can redistribute it and/or modify it
143 under the same terms as Perl itself.
144  
145 =cut
146  
147 2 1; # End of Catalyst::Plugin::ConfigLoader::Remote
↑ Summary