Catalyst::Plugin::ConfigLoader::Remote - Load (remote) URIs into config


Catalyst-Plugin-ConfigLoader-Remote documentation Contained in the Catalyst-Plugin-ConfigLoader-Remote distribution.

Index


Code Index:

NAME

Top

Catalyst::Plugin::ConfigLoader::Remote - Load (remote) URIs into config

VERSION

Top

Version 0.01

SYNOPSIS

Top

This module provides support for fetching remote configuration files over HTTP, FTP or other remote methods.

It will fetch any blessed URI object in the files config entry for the package via File::Fetch

 package MyApp;

 use Catalyst qw/ConfigLoader::Remote/;

 use URI;

 __PACKAGE__->config(
    'Plugin::ConfigLoader::Remote' => {
        files => [
            URI->new("https://secure.example.com/config/basic.yml"),
            URI->new("https://secure.example.com/config/database.conf"),
        ]
    }
 );

METHODS

Top

find_files

find_files will download each file to a temporary directory that is purged on program exit. It is then passed to Catalyst::Plugin::ConfigLoader for actual configuration loading and processing.

AUTHOR

Top

J. Shirley, <jshirley at gmail.com>

Eden Cardim

BUGS

Top

Please report any bugs or feature requests to bug-catalyst-plugin-configloader-remote at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Catalyst-Plugin-ConfigLoader-Remote. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.

SUPPORT

Top

You can find documentation for this module with the perldoc command.

    perldoc Catalyst::Plugin::ConfigLoader::Remote

You can also look for information at:

* AnnoCPAN: Annotated CPAN documentation

http://annocpan.org/dist/Catalyst-Plugin-ConfigLoader-Remote

* CPAN Ratings

http://cpanratings.perl.org/d/Catalyst-Plugin-ConfigLoader-Remote

* RT: CPAN's request tracker

http://rt.cpan.org/NoAuth/Bugs.html?Dist=Catalyst-Plugin-ConfigLoader-Remote

* Search CPAN

http://search.cpan.org/dist/Catalyst-Plugin-ConfigLoader-Remote

ACKNOWLEDGEMENTS

Top

COPYRIGHT & LICENSE

Top


Catalyst-Plugin-ConfigLoader-Remote documentation Contained in the Catalyst-Plugin-ConfigLoader-Remote distribution.
package Catalyst::Plugin::ConfigLoader::Remote;

use warnings;
use strict;

use File::Fetch;
use Scalar::Util qw(blessed);
use File::Temp qw/tempdir/;

use MRO::Compat;

use base qw/Catalyst::Plugin::ConfigLoader/;

our $VERSION = '0.02';

sub find_files {
    my $c = shift;

    my $tempdir = tempdir( CLEANUP => 1 );

    # Load up the other files that are coming in.
    my @files = $c->next::method();

    my $config = $c->config->{'Plugin::ConfigLoader::Remote'};

    return @files unless ref $config eq 'HASH' and
                         ref $config->{files} eq 'ARRAY';

    my @incoming_files =
        @{ $config->{files} };

    # replace everything in @files that is a URI object with a downloaded copy
    foreach my $arg ( @incoming_files ) {
        if ( blessed $arg and $arg->isa('URI') ) {
            # Fetch a blessed URI
            my $ff = File::Fetch->new( uri => $arg->as_string );
            if ( $ff ) {
                my $file = $ff->fetch( to => $tempdir );
                if ( $file and -f $file ) {
                    push @files, $file;
                }
            }
        } else {
            push @files, $arg;
        }
    }

    return @files;
}

1; # End of Catalyst::Plugin::ConfigLoader::Remote