]> nmode's Git Repositories - Fey/blobdiff - lib/App/Fey.pm
Allow reading files/URIs from STDIN
[Fey] / lib / App / Fey.pm
index 7b287f07e185cfeeb2ca1d70adcbbfa923842e7a..8b802a0d70e7a1881af2e3bcf1baae2a074a7051 100644 (file)
@@ -27,6 +27,13 @@ sub launch {
     my $self = shift;
     my $options = ref $_[0] ? shift : {};
 
     my $self = shift;
     my $options = ref $_[0] ? shift : {};
 
+    if (!(-t STDIN)) {
+        _read_stdin(\@_);
+    }
+    if (!@_ || $options->{interactive}) {
+        open STDIN, '<', '/dev/tty'; 
+        _read_stdin(\@_);
+    }
     die "No files or URIs specified.\n" unless @_;
 
     if ($options->{group}) {
     die "No files or URIs specified.\n" unless @_;
 
     if ($options->{group}) {
@@ -129,6 +136,13 @@ sub _get_handler {
     }
 }
 
     }
 }
 
+sub _read_stdin {
+    for my $file_or_uri (<STDIN>) {
+        chomp $file_or_uri;
+        push @{ $_[0] }, $file_or_uri;
+    }
+}
+
 sub fey {
     App::Fey->new(ref $_[0] ? $_[0] : {})->launch(@_);
 }
 sub fey {
     App::Fey->new(ref $_[0] ? $_[0] : {})->launch(@_);
 }