X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FMooseX%2FConfigFromFile.pm;h=59d3e3ebd50b8235a950d587f165f0ee7e15ef28;hb=23fca8d5bbae73c0b80881f86126a86818035d6d;hp=6214934c2ae862af0699a29896b4f83b0bb240fb;hpb=28d693631e3b72ea26dc51fb9c4d84ce718dbde1;p=gitmo%2FMooseX-ConfigFromFile.git diff --git a/lib/MooseX/ConfigFromFile.pm b/lib/MooseX/ConfigFromFile.pm index 6214934..59d3e3e 100644 --- a/lib/MooseX/ConfigFromFile.pm +++ b/lib/MooseX/ConfigFromFile.pm @@ -1,7 +1,8 @@ package MooseX::ConfigFromFile; +# ABSTRACT: An abstract Moose role for setting attributes from a configfile use Moose::Role; -use MooseX::Types::Path::Tiny 'Path'; +use MooseX::Types::Path::Tiny 0.005 'Path'; use MooseX::Types::Moose 'Undef'; use Try::Tiny; use Carp qw(croak); @@ -9,11 +10,6 @@ use namespace::autoclean; requires 'get_config_from_file'; -# overridable in consuming class or role to provide a default value -# This is called before instantiation, so it must be a class method, -# and not depend on any other attributes -sub _get_default_configfile { } - has configfile => ( is => 'ro', isa => Path|Undef, @@ -23,7 +19,10 @@ has configfile => ( lazy => 1, # it sucks that we have to do this rather than using a builder, but some old code # simply swaps in a new default sub into the attr definition - default => sub { shift->_get_default_configfile }, + default => sub { + my $class = shift; + $class->_get_default_configfile if $class->can('_get_default_configfile'); + }, ); sub new_with_config { @@ -37,7 +36,7 @@ sub new_with_config { else { # This would only succeed if the consumer had defined a new configfile # sub to override the generated reader - as suggested in old - # documentation + # documentation -- or if $class is an instance not a class name $configfile = try { $class->configfile }; # this is gross, but since a lot of users have swapped in their own @@ -73,10 +72,6 @@ __END__ =pod -=head1 NAME - -MooseX::ConfigFromFile - An abstract Moose role for setting attributes from a configfile - =head1 SYNOPSIS ######## @@ -128,6 +123,8 @@ It declares an attribute C and a class method C, and requires that concrete roles derived from it implement the class method C. +=for stopwords configfile + Attributes specified directly as arguments to C supersede those in the configfile. @@ -170,35 +167,8 @@ a hashref of arguments to pass to C which are sourced from the configfile =head2 _get_default_configfile -This class method returns nothing by default, but can and should be redefined -in a consuming class to return the default value of the configfile (if not +This class method is not implemented in this role, but can and should be defined +in a consuming class or role to return the default value of the configfile (if not passed into the constructor explicitly). -=head1 COPYRIGHT - -Copyright (c) - the MooseX::ConfigFromFile "AUTHOR" and "CONTRIBUTORS" as listed below. - -=head1 AUTHOR - -Brandon L. Black, Eblblack@gmail.comE - -=head1 CONTRIBUTORS - -=over - -=item Tomas Doran - -=item Karen Etheridge - -=item Chris Prather - -=item Zbigniew Lukasiak - -=back - -=head1 LICENSE - -This library is free software; you can redistribute it and/or modify -it under the same terms as Perl itself. - =cut