Permalink
Browse files

create a readme automatically

  • Loading branch information...
1 parent 0418025 commit 73cae276a130878efbeb32ac4a6180341ee455fe @2shortplanks committed Jul 16, 2012
Showing with 254 additions and 0 deletions.
  1. +2 −0 CHANGES
  2. +2 −0 MANIFEST
  3. +5 −0 META.yml
  4. +1 −0 Makefile.PL
  5. +106 −0 README
  6. +138 −0 inc/Module/Install/ReadmeFromPod.pm
View
@@ -1,3 +1,5 @@
+1.01 Added readme
+
1.00 2012-05-15
- Initial Release
View
@@ -7,12 +7,14 @@ inc/Module/Install/Fetch.pm
inc/Module/Install/GithubMeta.pm
inc/Module/Install/Makefile.pm
inc/Module/Install/Metadata.pm
+inc/Module/Install/ReadmeFromPod.pm
inc/Module/Install/Win32.pm
inc/Module/Install/WriteAll.pm
lib/Array/Windowed.pm
Makefile.PL
MANIFEST This list of files
META.yml
+README
t/01basic.t
xt/001pod.t
xt/002podcoverage.t
View
@@ -20,5 +20,10 @@ no_index:
- t
- xt
resources:
+ homepage: https://github.com/2shortplanks/Array-Windowed/tree
license: http://dev.perl.org/licenses/
+ repository:
+ type: git
+ url: git://github.com/2shortplanks/Array-Windowed.git
+ web: https://github.com/2shortplanks/Array-Windowed/tree
version: 1.00
View
@@ -6,5 +6,6 @@ all_from 'lib/Array/Windowed.pm';
license 'perl';
githubmeta;
author_tests('xt');
+readme_from 'lib/Array/Windowed.pm';
WriteAll;
View
106 README
@@ -0,0 +1,106 @@
+NAME
+ Array::Windowed - return a windowed slice of the array
+
+SYNOPSIS
+ use Array::Windowed qw(windowed_array);
+
+ # from an array
+ my $new_array = array_window @old_array, $start_index, $count);
+
+ # from an arrayref
+ my $new_array2 = &array_window($array_ref, $start_index, $count);
+
+DESCRIPTION
+ Simple module to return a slice of the passed array as specified by a
+ start position and a number of elements. Unlike the built in slicing
+ functions this does not populate the returned array with "undef"s for
+ out of bounds operations, but simply returns a smaller array.
+
+FUNCTION
+ Exported on demand (or you can call it fully qualified)
+
+ array_windowed @old_array, $start_index, $count
+ Returns an array reference containing up to $count elements from the
+ @old_array starting at $start_index.
+
+ Unlike a traditional array slice elements outside the bounds of the
+ array are simply dropped. Negative indexes are treated as normal
+ indexes that occur before the 0th index (rather than indexes
+ counting backwards from the start of the array.)
+
+ This is probably best shown with a series of examples:
+
+ my @array = ['a'..'z'];
+
+ # ["a".."z"]
+ array_windowed(@array, 0, 26);
+
+ # ["a","b","c","d","e"]
+ array_windowed(@array, 0, 5);
+
+ # ["b","c","d","e","f"]
+ array_windowed(@array, 1, 5);
+
+ # []
+ array_windowed(@array, 26, 5);
+
+ # []
+ array_windowed(@array, -50, 5);
+
+ # ["x","y","z"]
+ array_windowed(@array, 23, 5);
+
+ # ["a","b","c"]
+ array_windowed(@array, -2, 5);
+
+ # ["a".."z"]
+ &array_windowed(\@array, 0, 26);
+
+RATIONALLE
+ Why this module?
+
+ Why not simple array slices with @foo[ ... ]
+ Because the edge cases of indexes outside the bounds of the array
+ don't do the same thing (they return lots of "undef"s mainly)
+
+ Why not splice?
+ It's destructive on the original array.
+
+ Why not Array::Window
+ Because it tries too hard to DTRT, which isn't the RT for us. For
+ example, if you have a count bigger than the entire array then it
+ always returns the entire array irregardless of the start position.
+
+ This doesn't mean it's not the module for you, however.
+
+ Why not Data::Page
+ This concept of windowing we're using doesn't use pages, but rather
+ a start position and a count.
+
+ This doesn't mean it's not the module for you, however.
+
+AUTHOR
+ Written by Mark Fowler <mark@twoshortplanks.com>
+
+COPYRIGHT
+ Copyright Mark Fowler 2012. All Rights Reserved.
+
+ This program is free software; you can redistribute it and/or modify it
+ under the same terms as Perl itself.
+
+BUGS
+ This module does no sanity checking on the values that are passed into
+ it (i.e. it does not check that $start or $count are integer numbers,
+ nor does it check that the first argument is an array reference if you
+ disable prototyping.)
+
+ Bugs should be reported via this distribution's CPAN RT queue. This can
+ be found at <https://rt.cpan.org/Dist/Display.html?Array-Windowed>
+
+ You can also address issues by forking this distribution on github and
+ sending pull requests. It can be found at
+ <http://github.com/2shortplanks/Array-Windowed>
+
+SEE ALSO
+ Array::Window, Data::Page
+
@@ -0,0 +1,138 @@
+#line 1
+package Module::Install::ReadmeFromPod;
+
+use 5.006;
+use strict;
+use warnings;
+use base qw(Module::Install::Base);
+use vars qw($VERSION);
+
+$VERSION = '0.18';
+
+sub readme_from {
+ my $self = shift;
+ return unless $self->is_admin;
+
+ # Input file
+ my $in_file = shift || $self->_all_from
+ or die "Can't determine file to make readme_from";
+
+ # Get optional arguments
+ my ($clean, $format, $out_file, $options);
+ my $args = shift;
+ if ( ref $args ) {
+ # Arguments are in a hashref
+ if ( ref($args) ne 'HASH' ) {
+ die "Expected a hashref but got a ".ref($args)."\n";
+ } else {
+ $clean = $args->{'clean'};
+ $format = $args->{'format'};
+ $out_file = $args->{'output_file'};
+ $options = $args->{'options'};
+ }
+ } else {
+ # Arguments are in a list
+ $clean = $args;
+ $format = shift;
+ $out_file = shift;
+ $options = \@_;
+ }
+
+ # Default values;
+ $clean ||= 0;
+ $format ||= 'txt';
+
+ # Generate README
+ print "readme_from $in_file to $format\n";
+ if ($format =~ m/te?xt/) {
+ $out_file = $self->_readme_txt($in_file, $out_file, $options);
+ } elsif ($format =~ m/html?/) {
+ $out_file = $self->_readme_htm($in_file, $out_file, $options);
+ } elsif ($format eq 'man') {
+ $out_file = $self->_readme_man($in_file, $out_file, $options);
+ } elsif ($format eq 'pdf') {
+ $out_file = $self->_readme_pdf($in_file, $out_file, $options);
+ }
+
+ if ($clean) {
+ $self->clean_files($out_file);
+ }
+
+ return 1;
+}
+
+
+sub _readme_txt {
+ my ($self, $in_file, $out_file, $options) = @_;
+ $out_file ||= 'README';
+ require Pod::Text;
+ my $parser = Pod::Text->new( @$options );
+ open my $out_fh, '>', $out_file or die "Could not write file $out_file:\n$!\n";
+ $parser->output_fh( *$out_fh );
+ $parser->parse_file( $in_file );
+ close $out_fh;
+ return $out_file;
+}
+
+
+sub _readme_htm {
+ my ($self, $in_file, $out_file, $options) = @_;
+ $out_file ||= 'README.htm';
+ require Pod::Html;
+ Pod::Html::pod2html(
+ "--infile=$in_file",
+ "--outfile=$out_file",
+ @$options,
+ );
+ # Remove temporary files if needed
+ for my $file ('pod2htmd.tmp', 'pod2htmi.tmp') {
+ if (-e $file) {
+ unlink $file or warn "Warning: Could not remove file '$file'.\n$!\n";
+ }
+ }
+ return $out_file;
+}
+
+
+sub _readme_man {
+ my ($self, $in_file, $out_file, $options) = @_;
+ $out_file ||= 'README.1';
+ require Pod::Man;
+ my $parser = Pod::Man->new( @$options );
+ $parser->parse_from_file($in_file, $out_file);
+ return $out_file;
+}
+
+
+sub _readme_pdf {
+ my ($self, $in_file, $out_file, $options) = @_;
+ $out_file ||= 'README.pdf';
+ eval { require App::pod2pdf; }
+ or die "Could not generate $out_file because pod2pdf could not be found\n";
+ my $parser = App::pod2pdf->new( @$options );
+ $parser->parse_from_file($in_file);
+ open my $out_fh, '>', $out_file or die "Could not write file $out_file:\n$!\n";
+ select $out_fh;
+ $parser->output;
+ select STDOUT;
+ close $out_fh;
+ return $out_file;
+}
+
+
+sub _all_from {
+ my $self = shift;
+ return unless $self->admin->{extensions};
+ my ($metadata) = grep {
+ ref($_) eq 'Module::Install::Metadata';
+ } @{$self->admin->{extensions}};
+ return unless $metadata;
+ return $metadata->{values}{all_from} || '';
+}
+
+'Readme!';
+
+__END__
+
+#line 254
+

0 comments on commit 73cae27

Please sign in to comment.