From: John Napiorkowski Date: Thu, 5 Jun 2008 02:29:38 +0000 (+0000) Subject: initial checkin X-Git-Tag: 0.02~4 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=gitmo%2FMooseX-Attribute-ENV.git;a=commitdiff_plain;h=650d6350b430235d0b48a7bb05927558eb155ceb initial checkin --- 650d6350b430235d0b48a7bb05927558eb155ceb diff --git a/Changes b/Changes new file mode 100644 index 0000000..53e25f5 --- /dev/null +++ b/Changes @@ -0,0 +1,4 @@ +Revision history for Perl extension MooseX-Attribute-ENV. + +0.01 Tues, 05 June 2008 + - Initial release diff --git a/MANIFEST.SKIP b/MANIFEST.SKIP new file mode 100644 index 0000000..d164814 --- /dev/null +++ b/MANIFEST.SKIP @@ -0,0 +1,40 @@ + +# Avoid version control files. +\bRCS\b +\bCVS\b +,v$ +\B\.svn\b + +# Avoid Makemaker generated and utility files. +\bMakefile$ +\bblib +\bMakeMaker-\d +\bpm_to_blib$ +\bblibdirs$ +^MANIFEST\.SKIP$ + +# for developers only :) +^TODO$ +^VERSIONING\.SKETCH$ + +# Avoid Module::Build generated and utility files. +\bBuild$ +\b_build + +# Avoid temp and backup files. +~$ +\.tmp$ +\.old$ +\.bak$ +\#$ +\b\.# + +# avoid OS X finder files +\.DS_Store$ + + +# Don't ship the last dist we built :) +\.tar\.gz$ + +# Skip maint stuff +^maint/ \ No newline at end of file diff --git a/Makefile.PL b/Makefile.PL new file mode 100644 index 0000000..7e338af --- /dev/null +++ b/Makefile.PL @@ -0,0 +1,16 @@ +use inc::Module::Install; + +perl_version '5.008006'; +name 'MooseX-Attribute-ENV'; +all_from 'lib/MooseX/Attribute/ENV.pm'; +author 'John Napiorkowski '; + +requires 'Moose' => '0.48'; + +build_requires 'Test::More'; +build_requires 'File::Find'; + +auto_install; + +WriteAll; + diff --git a/README b/README new file mode 100644 index 0000000..c6c9a24 --- /dev/null +++ b/README @@ -0,0 +1,69 @@ +MooseX-Attribute-ENV + +This is a L attribute trait that you use when you want the default value +for an attribute to be populated from the %ENV hash. So, for example if you +have set the environment variable MYAPP_MYCLASS_USERNAME = 'John' you can do: + + package MyApp::MyClass; + + use Moose; + use MooseX::Attribute::ENV; + + has 'username' => (is=>'ro', traits=>['ENV']); + + package main; + + my $myclass = MyApp::MyClass->new(); + + print $myclass->username; # STDOUT => 'John'; + +This is basically similar functionality to something like: + + has 'attr' => ( + is=>'ro', + default=> sub { + $ENV{uc __PACKAGE_.'attr'}; + }, + ); + +but this module has a few other features that offer merit, as well as being a +simple enough attribute trait that I hope it can serve as a learning tool. + +INSTALLATION + +To install this module, run the following commands: + + perl Makefile.PL + make + make test + make install + +SUPPORT AND DOCUMENTATION + +After installing, you can find documentation for this module with the +perldoc command. + + perldoc MooseX-Attribute-ENV + +You can also look for information at: + + RT, CPAN's request tracker + http://rt.cpan.org/NoAuth/Bugs.html?Dist=MooseX-Attribute-ENV + + AnnoCPAN, Annotated CPAN documentation + http://annocpan.org/dist/MooseX-Attribute-ENV + + CPAN Ratings + http://cpanratings.perl.org/d/MooseX-Attribute-ENV + + Search CPAN + http://search.cpan.org/dist/MooseX-Attribute-ENV + + +COPYRIGHT AND LICENCE + +Copyright (C) 2008 John Napiorkowski + +This program is free software; you can redistribute it and/or modify it +under the same terms as Perl itself. + diff --git a/lib/MooseX/Attribute/ENV.pm b/lib/MooseX/Attribute/ENV.pm new file mode 100644 index 0000000..cbfd96f --- /dev/null +++ b/lib/MooseX/Attribute/ENV.pm @@ -0,0 +1,120 @@ +package MooseX::Attribute::ENV; + + +=head1 NAME + +MooseX::Attribute::ENV - Set default of an attribute to a value from %ENV + +=head1 VERSION + +Version 0.01 + +=cut + +our $VERSION = '0.01'; + +=head1 SYNOPSIS + +The following is example usage for this component. + + package Myapp::MyClass; + + use Moose; + use MooseX::Attribute::ENV; + + has 'username' => (traits => ['ENV']); + has 'password' => (traits => ['ENV'], env_key => 'GLOBAL_PASSWORD'); + has 'last_login' => (traits => ['ENV'], default => sub {localtime} ); + +Please see the test cases for more detailed examples. + +=head1 DESCRIPTION + +This is a L attribute trait that you use when you want the default value +for an attribute to be populated from the %ENV hash. So, for example if you +have set the environment variable MYAPP_MYCLASS_USERNAME = 'John' you can do: + + package MyApp::MyClass; + + use Moose; + use MooseX::Attribute::ENV; + + has 'username' => (is=>'ro', traits=>['ENV']); + + package main; + + my $myclass = MyApp::MyClass->new(); + + print $myclass->username; # STDOUT => 'John'; + +This is basically similar functionality to something like: + + has 'attr' => ( + is=>'ro', + default=> sub { + $ENV{uc __PACKAGE_.'attr'}; + }, + ); + +but this module has a few other features that offer merit, as well as being a +simple enough attribute trait that I hope it can serve as a learning tool. It +also does it's best to respect existing builders, defaults and lazy_build +options. + +=head1 METHODS + +This module defines the following methods. + +=head1 AUTHOR + +John Napiorkowski, C<< >> + +=head1 BUGS + +Please report any bugs or feature requests to: + + C + +or through the web interface at: + + L + +I will be notified, and then you'll automatically be notified of progress on +your bug as I make changes. + +=head1 SUPPORT + +You can find documentation for this module with the perldoc command. + + perldoc MooseX::Attribute::ENV + +You can also look for information at: + +=over 4 + +=item * RT: CPAN's request tracker + +L + +=item * AnnoCPAN: Annotated CPAN documentation + +L + +=item * CPAN Ratings + +L + +=item * Search CPAN + +L + +=back + +=head1 LICENSE + +This program is free software; you can redistribute it and/or modify it +under the same terms as Perl itself. + +=cut + +1; diff --git a/t-author/newlines.t b/t-author/newlines.t new file mode 100644 index 0000000..9264562 --- /dev/null +++ b/t-author/newlines.t @@ -0,0 +1,117 @@ +use strict; +use warnings; + +BEGIN { + + use Test::More; + use File::Find; +} + + +=head1 NAME + +t/newlines.t - test to make sure all text files are in unix linefeed format + +=head1 DESCRIPTION + +Descends through the distribution directory and verifies that all text files +(files with an extention matching a pattern, such as *.txt) are in unix +linefeed format. + +=head1 TESTS + +This module defines the following tests. + +=head2 Descend Distribution + +Starting at the Distribution root, look at all files in all subdirections and +if the file matches a text type (according to a particular regex for it's +extension) add it to a files of files to test. + +=cut + +my @files; + + find({ + wanted => \&process, + follow => 0 + }, '.'); + +sub process +{ + my $file = $_; + + return if $File::Find::dir =~m/\.svn/; + return if $File::Find::dir =~m/archive/; + + push @files, $File::Find::name + if $file =~m/\.yml$|\.pm$|\.pod$|\.tt$|\.txt$|\.js$|\.css$|\.sql$|\.html$/; +} + + +=head2 test linefeedtype + +Check if the generated files are correctly unix linefeeds + +=cut + +my $CR = "\015"; # Apple II family, Mac OS thru version 9 +my $CRLF = "\015\012"; # CP/M, MP/M, DOS, Microsoft Windows +my $FF = "\014"; # printer form feed +my $LF = "\012"; # Unix, Linux, Xenix, Mac OS X, BeOS, Amiga + +my $test_builder = Test::More->builder; + +if( $#files ) +{ + $test_builder->plan(tests => ($#files+1)*2); + + foreach my $file (@files) + { + ## Get a good filehandle + open( my $fh, '<', $file) + or fail "Can't open $file, can't finish testing"; + + ## Only need to test the first line. + my ($first, $second) = <$fh>; + + ## Don't need this anymore + close($fh); + + SKIP: { + + skip "$file is Empty!", 2 unless $first; + + ## Are we DOS or MACOS/APPLE? + ok $first!~m/$CRLF$|$CR$|$FF$/, "$file isn't in a forbidden format"; + + ## If there is more than one line, we HAVE to be UNIX + + SKIP: { + + skip "$file only has a single line", 1 unless $second; + ok $first=~m/$LF$/, "$file Is unix linefeed"; + } + } + } +} +else +{ + $test_builder->plan(skip_all => 'No Text Files Found! (This is probably BIG Trouble...'); +} + +=head1 AUTHOR + +John Napiorkowski, C<< >> + +=head1 COPYRIGHT & LICENSE + +Copyright 2008 John Napiorkowski. + +This program is free software; you can redistribute it and/or modify it +under the same terms as Perl itself. + +=cut + + +1; \ No newline at end of file diff --git a/t-author/pod-coverage.t b/t-author/pod-coverage.t new file mode 100644 index 0000000..fc40a57 --- /dev/null +++ b/t-author/pod-coverage.t @@ -0,0 +1,18 @@ +use strict; +use warnings; +use Test::More; + +# Ensure a recent version of Test::Pod::Coverage +my $min_tpc = 1.08; +eval "use Test::Pod::Coverage $min_tpc"; +plan skip_all => "Test::Pod::Coverage $min_tpc required for testing POD coverage" + if $@; + +# Test::Pod::Coverage doesn't require a minimum Pod::Coverage version, +# but older versions don't recognize some common documentation styles +my $min_pc = 0.18; +eval "use Pod::Coverage $min_pc"; +plan skip_all => "Pod::Coverage $min_pc required for testing POD coverage" + if $@; + +all_pod_coverage_ok(); diff --git a/t-author/pod.t b/t-author/pod.t new file mode 100644 index 0000000..ee8b18a --- /dev/null +++ b/t-author/pod.t @@ -0,0 +1,12 @@ +#!perl -T + +use strict; +use warnings; +use Test::More; + +# Ensure a recent version of Test::Pod +my $min_tp = 1.22; +eval "use Test::Pod $min_tp"; +plan skip_all => "Test::Pod $min_tp required for testing POD" if $@; + +all_pod_files_ok(); diff --git a/t/00-load.t b/t/00-load.t new file mode 100644 index 0000000..f4686ca --- /dev/null +++ b/t/00-load.t @@ -0,0 +1,10 @@ +use warnings; +use strict; + +use MooseX::Attribute::ENV; +use Test::More tests => 1; + +diag( "Testing MooseX::Attribute::ENV $MooseX::Attribute::ENV::VERSION, Perl $], $^X" ); +use_ok( 'MooseX::Attribute::ENV' ); + +