From 5efa5f56cf74ed3a9898e766ecdb2bb7f27dc943 Mon Sep 17 00:00:00 2001 From: Shawn Boyette Date: Wed, 18 Mar 2009 05:35:11 +0000 Subject: [PATCH] adding modular stuffs --- Equinox-Migration/.cvsignore | 10 + Equinox-Migration/Changes | 5 + Equinox-Migration/MANIFEST | 8 + Equinox-Migration/Makefile.PL | 16 ++ Equinox-Migration/README | 52 +++++ Equinox-Migration/lib/Equinox/Migration.pm | 107 ++++++++++ .../lib/Equinox/Migration/SimpleTagList.pm | 212 ++++++++++++++++++++ Equinox-Migration/t/00-load.t | 9 + Equinox-Migration/t/boilerplate.t | 55 +++++ Equinox-Migration/t/pod-coverage.t | 18 ++ Equinox-Migration/t/pod.t | 12 + 11 files changed, 504 insertions(+), 0 deletions(-) create mode 100644 Equinox-Migration/.cvsignore create mode 100644 Equinox-Migration/Changes create mode 100644 Equinox-Migration/MANIFEST create mode 100644 Equinox-Migration/Makefile.PL create mode 100644 Equinox-Migration/README create mode 100644 Equinox-Migration/lib/Equinox/Migration.pm create mode 100644 Equinox-Migration/lib/Equinox/Migration/SimpleTagList.pm create mode 100644 Equinox-Migration/t/00-load.t create mode 100644 Equinox-Migration/t/boilerplate.t create mode 100644 Equinox-Migration/t/pod-coverage.t create mode 100644 Equinox-Migration/t/pod.t diff --git a/Equinox-Migration/.cvsignore b/Equinox-Migration/.cvsignore new file mode 100644 index 0000000..f321146 --- /dev/null +++ b/Equinox-Migration/.cvsignore @@ -0,0 +1,10 @@ +blib* +Makefile +Makefile.old +Build +_build* +pm_to_blib* +*.tar.gz +.lwpcookies +Equinox-Migration-* +cover_db diff --git a/Equinox-Migration/Changes b/Equinox-Migration/Changes new file mode 100644 index 0000000..0a0ada6 --- /dev/null +++ b/Equinox-Migration/Changes @@ -0,0 +1,5 @@ +Revision history for Equinox-Migration + +0.01 Date/time + First version, released on an unsuspecting world. + diff --git a/Equinox-Migration/MANIFEST b/Equinox-Migration/MANIFEST new file mode 100644 index 0000000..8c98c80 --- /dev/null +++ b/Equinox-Migration/MANIFEST @@ -0,0 +1,8 @@ +Changes +MANIFEST +Makefile.PL +README +lib/Equinox/Migration.pm +t/00-load.t +t/pod-coverage.t +t/pod.t diff --git a/Equinox-Migration/Makefile.PL b/Equinox-Migration/Makefile.PL new file mode 100644 index 0000000..9d972c2 --- /dev/null +++ b/Equinox-Migration/Makefile.PL @@ -0,0 +1,16 @@ +use strict; +use warnings; +use ExtUtils::MakeMaker; + +WriteMakefile( + NAME => 'Equinox::Migration', + AUTHOR => 'Shawn Boyette ', + VERSION_FROM => 'lib/Equinox/Migration.pm', + ABSTRACT_FROM => 'lib/Equinox/Migration.pm', + PL_FILES => {}, + PREREQ_PM => { + 'Test::More' => 0, + }, + dist => { COMPRESS => 'gzip -9f', SUFFIX => 'gz', }, + clean => { FILES => 'Equinox-Migration-*' }, +); diff --git a/Equinox-Migration/README b/Equinox-Migration/README new file mode 100644 index 0000000..3d0f9c2 --- /dev/null +++ b/Equinox-Migration/README @@ -0,0 +1,52 @@ +Equinox-Migration + +The README is used to introduce the module and provide instructions on +how to install the module, any machine dependencies it may have (for +example C compilers and installed libraries) and any other information +that should be provided before the module is installed. + +A README file is required for CPAN modules since CPAN extracts the README +file from a module distribution so that people browsing the archive +can use it to get an idea of the module's uses. It is usually a good idea +to provide version information here so that people can decide whether +fixes for the module are worth downloading. + + +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 Equinox::Migration + +You can also look for information at: + + RT, CPAN's request tracker + http://rt.cpan.org/NoAuth/Bugs.html?Dist=Equinox-Migration + + AnnoCPAN, Annotated CPAN documentation + http://annocpan.org/dist/Equinox-Migration + + CPAN Ratings + http://cpanratings.perl.org/d/Equinox-Migration + + Search CPAN + http://search.cpan.org/dist/Equinox-Migration + + +COPYRIGHT AND LICENCE + +Copyright (C) 2009 Shawn Boyette + +This program is free software; you can redistribute it and/or modify it +under the same terms as Perl itself. + diff --git a/Equinox-Migration/lib/Equinox/Migration.pm b/Equinox-Migration/lib/Equinox/Migration.pm new file mode 100644 index 0000000..8a7a504 --- /dev/null +++ b/Equinox-Migration/lib/Equinox/Migration.pm @@ -0,0 +1,107 @@ +package Equinox::Migration; + +use warnings; +use strict; + +=head1 NAME + +Equinox::Migration - The great new Equinox::Migration! + +=head1 VERSION + +Version 0.01 + +=cut + +our $VERSION = '0.01'; + + +=head1 SYNOPSIS + +Quick summary of what the module does. + +Perhaps a little code snippet. + + use Equinox::Migration; + + my $foo = Equinox::Migration->new(); + ... + +=head1 EXPORT + +A list of functions that can be exported. You can delete this section +if you don't export anything, such as for a purely object-oriented module. + +=head1 FUNCTIONS + +=head2 function1 + +=cut + +sub function1 { +} + +=head2 function2 + +=cut + +sub function2 { +} + +=head1 AUTHOR + +Shawn Boyette, 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 Equinox::Migration + + +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 ACKNOWLEDGEMENTS + + +=head1 COPYRIGHT & LICENSE + +Copyright 2009 Shawn Boyette, all rights reserved. + +This program is free software; you can redistribute it and/or modify it +under the same terms as Perl itself. + + +=cut + +1; # End of Equinox::Migration diff --git a/Equinox-Migration/lib/Equinox/Migration/SimpleTagList.pm b/Equinox-Migration/lib/Equinox/Migration/SimpleTagList.pm new file mode 100644 index 0000000..0fd50db --- /dev/null +++ b/Equinox-Migration/lib/Equinox/Migration/SimpleTagList.pm @@ -0,0 +1,212 @@ +package Equinox::Migration::SimpleTagList; + +use warnings; +use strict; + +=head1 NAME + +Equinox::Migration::SimpleTagList - Generate taglist from file + +=head1 VERSION + +Version 1.000 + +=cut + +our $VERSION = '1.000'; + + +=head1 SYNOPSIS + +Using a file as input, E::M::STL generates a set of MARC tags +(three-digit, zero-padded integers) and provides several access +mechanisms to that list. + + use Equinox::Migration::SimpleTagList; + + my $stl = Equinox::Migration::SimpleTagList->new( file => "trashtags.txt" ); + my $tags = $stl->as_hashref; + +or + + my $stl = Equinox::Migration::SimpleTagList->new( file => "trashtags.txt" ); + if ( $stl->has($foo) ) { + # if $foo is an element of $stl's parsed list + # do stuff ... + } + + +=head1 ROUTINES + + +=head2 new + +Takes one argument, C, which is mandatory. Returns a E::M::STL +object. + +=cut + +sub new { + my ($class,%args) = @_; + + my $self = bless { conf => { except => 0, + range => { high => 0, low => 0 }, + }, + tags => {} }, $class; + + if (-r $args{file}) { + $self->{conf}{file} = $args{file} + } else { + die "Can't open tags file: $!\n"; + } + + $self->generate; + return $self; +} + + + +=head2 has + +Passed a data field tag, returns 1 if that tag is in the list and 0 if +it is not. + +=cut + +sub has { my ($self, $t) = @_; return (defined $self->{tags}{$t}) ? 1 : 0 } + +=head2 as_hashref + +Returns a hashref of the entire, assembled tag list. + +=cut + +sub as_hashref { my ($self) = @_; return $self->{tags} } + +=head2 as_hashref + +Returns a listref of the entire, assembled tag list. + +=cut + +sub as_listref { my ($self) = @_; return \(keys %{$self->{tags}}) } + +sub generate { + my ($self) = @_; + + open TAGFILE, '<', $self->{conf}{file}; + while () { + my $lastwasrange = 0; + $self->{conf}{range}{high} = 0; + $self->{conf}{range}{low} = 0; + $self->{conf}{except} = 0; + + my @chunks = split /\s+/; + while (my $chunk = shift @chunks) { + + # single values + if ($chunk =~ /^\d{1,3}$/) { + $self->add_tag($chunk); + $lastwasrange = 0; + next; + } + + # ranges + if ($chunk =~ /^\d{1,3}\.\.\d{1,3}$/) { + my ($low, $high) = $self->add_range($chunk); + $lastwasrange = 1; + unless ($self->{conf}{except}) { + $self->{conf}{range}{high} = $high; + $self->{conf}{range}{low} = $low; + } + next; + } + + # 'except' + if ($chunk eq 'except') { + die "Keyword 'except' can only follow a range (line $.)\n" + unless $lastwasrange; + die "Keyword 'except' may only occur once per line (line $.)\n" + if $self->{conf}{except}; + $$self->{conf}{except} = 1; + next; + } + + die "Unknown chunk $chunk in tags file (line $.)\n"; + } + } +} + +=head2 add_range + +=cut + +sub add_range { + my ($self, $chunk) = @_; + my ($low,$high) = split /\.\./, $chunk; + die "Ranges must be 'low..high' ($low is greater than $high on line $.)\n" + if ($low > $high); + if ($self->{conf}{except}) { + die "Exception ranges must be within last addition range (line $.)\n" + if ($low < $self->{range}{low} or $high > $self->{range}{high}); + } + for my $tag ($low..$high) { + $self->add_tag($tag) + } + return $low, $high; +} + +=head2 add_tag + +=cut + +sub add_tag { + my ($self, $tag) = @_; + + die "Values must be valid tags (000-999)\n" + unless ($tag >= 0 and $tag <= 999); + + if ($self->{conf}{except}) { + delete $self->{tags}{$tag}; + } else { + die "Trash tag '$tag' specified twice (line $.)\n" + if $self->{tags}{$tag}; + $self->{tags}{$tag} = 1; + } +} + + +=head1 AUTHOR + +Shawn Boyette, C<< >> + +=head1 TODO + +=over + +=item * Remove single-except rule? + +=back + +=head1 BUGS + +Please report any bugs or feature requests to the above email address. + +=head1 SUPPORT + +You can find documentation for this module with the perldoc command. + + perldoc Equinox::Migration::TrashTags + + +=head1 COPYRIGHT & LICENSE + +Copyright 2009 Shawn Boyette, all rights reserved. + +This program is free software; you can redistribute it and/or modify it +under the same terms as Perl itself. + + +=cut + +1; # End of Equinox::Migration::SimpleTagList diff --git a/Equinox-Migration/t/00-load.t b/Equinox-Migration/t/00-load.t new file mode 100644 index 0000000..c21b332 --- /dev/null +++ b/Equinox-Migration/t/00-load.t @@ -0,0 +1,9 @@ +#!perl -T + +use Test::More tests => 1; + +BEGIN { + use_ok( 'Equinox::Migration' ); +} + +diag( "Testing Equinox::Migration $Equinox::Migration::VERSION, Perl $], $^X" ); diff --git a/Equinox-Migration/t/boilerplate.t b/Equinox-Migration/t/boilerplate.t new file mode 100644 index 0000000..3d75799 --- /dev/null +++ b/Equinox-Migration/t/boilerplate.t @@ -0,0 +1,55 @@ +#!perl -T + +use strict; +use warnings; +use Test::More tests => 3; + +sub not_in_file_ok { + my ($filename, %regex) = @_; + open( my $fh, '<', $filename ) + or die "couldn't open $filename for reading: $!"; + + my %violated; + + while (my $line = <$fh>) { + while (my ($desc, $regex) = each %regex) { + if ($line =~ $regex) { + push @{$violated{$desc}||=[]}, $.; + } + } + } + + if (%violated) { + fail("$filename contains boilerplate text"); + diag "$_ appears on lines @{$violated{$_}}" for keys %violated; + } else { + pass("$filename contains no boilerplate text"); + } +} + +sub module_boilerplate_ok { + my ($module) = @_; + not_in_file_ok($module => + 'the great new $MODULENAME' => qr/ - The great new /, + 'boilerplate description' => qr/Quick summary of what the module/, + 'stub function definition' => qr/function[12]/, + ); +} + +TODO: { + local $TODO = "Need to replace the boilerplate text"; + + not_in_file_ok(README => + "The README is used..." => qr/The README is used/, + "'version information here'" => qr/to provide version information/, + ); + + not_in_file_ok(Changes => + "placeholder date/time" => qr(Date/time) + ); + + module_boilerplate_ok('lib/Equinox/Migration.pm'); + + +} + diff --git a/Equinox-Migration/t/pod-coverage.t b/Equinox-Migration/t/pod-coverage.t new file mode 100644 index 0000000..fc40a57 --- /dev/null +++ b/Equinox-Migration/t/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/Equinox-Migration/t/pod.t b/Equinox-Migration/t/pod.t new file mode 100644 index 0000000..ee8b18a --- /dev/null +++ b/Equinox-Migration/t/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(); -- 1.7.2.5