Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make tidy_changelog work as a pipe with input '-' #30

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion lib/CPAN/Changes.pm
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,14 @@ sub new {
sub load {
my ( $class, $file, @args ) = @_;

open( my $fh, '<:raw', $file ) or die $!;
my $fh;
if ( $file eq '-' ) {
open( $fh, '<-' ) or die $!;
binmode($fh)
}
else {
open( $fh, '<:raw', $file ) or die $!;
}

my $content = do { local $/; <$fh> };

Expand Down
30 changes: 30 additions & 0 deletions t/tidy_changelog.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
use strict;
use warnings;

use Test::More;

{ # use filename
my $tidy_changes = qx{$^X -Ilib bin/tidy_changelog t/corpus/basic.changes};

is( $tidy_changes, <<" EOTIDY", "output correct (filename)" );
0.01 2010-06-16
- Initial release
EOTIDY
}

{ # use filtermode
my $basic_changes = do { local (@ARGV, $/) = ('t/corpus/basic.changes'); <> };
open( my $pipe, '|-', "$^X -Ilib bin/tidy_changelog - > pipe_basic.changes" ) or die "Cannot fork: $!";
print $pipe $basic_changes;
close( $pipe );

my $tidy_changes = do { local (@ARGV, $/) = ('pipe_basic.changes'); <> };
is( $tidy_changes, <<" EOTIDY", "output correct (pipe)" );
0.01 2010-06-16
- Initial release
EOTIDY

unlink 'pipe_basic.changes';
}

done_testing();