diff options
author | Eric Wong <e@80x24.org> | 2023-11-02 09:35:34 +0000 |
---|---|---|
committer | Eric Wong <e@80x24.org> | 2023-11-03 06:39:30 +0000 |
commit | bbccb5f1d90bf9605fc8473cb9f01bc453a82bf9 (patch) | |
tree | bcaab4c47b6ebf6bfbb99332a5906ce36b680925 /lib/PublicInbox/IO.pm | |
parent | cfe25e6aa966144a9c96d1ba2c301fd5e1bad79b (diff) | |
download | public-inbox-bbccb5f1d90bf9605fc8473cb9f01bc453a82bf9.tar.gz |
This is pretty convenient way to create files for diff generation in both WWW and lei. The test suite should also be able to take advantage of it.
Diffstat (limited to 'lib/PublicInbox/IO.pm')
-rw-r--r-- | lib/PublicInbox/IO.pm | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/lib/PublicInbox/IO.pm b/lib/PublicInbox/IO.pm index 63850a52..4c92566d 100644 --- a/lib/PublicInbox/IO.pm +++ b/lib/PublicInbox/IO.pm @@ -4,8 +4,9 @@ # supports reaping of children tied to a pipe or socket package PublicInbox::IO; use v5.12; -use parent qw(IO::Handle); +use parent qw(IO::Handle Exporter); use PublicInbox::DS qw(awaitpid); +our @EXPORT_OK = qw(write_file); # TODO: this can probably be the new home for read_all, try_cat # and maybe even buffered read/readline... @@ -51,4 +52,11 @@ sub DESTROY { $io->SUPER::DESTROY; } +sub write_file ($$@) { # mode, filename, LIST (for print) + use autodie qw(open close); + open(my $fh, shift, shift); + print $fh @_; + defined(wantarray) && !wantarray ? $fh : close $fh; +} + 1; |