Comments (5)
Capture::Tiny is designed to capture. Exception handling is an orthogonal concern that won't be included. You can already include any exception handling you want inside the capture block:
my ( $stdout, $stderr, $result ) = capture { eval { print "YES"; die; 1; } };
from capture-tiny.
You do not understand. I do not ask to do exception handling. I ask to change format of calling. This change allow 'capture' even in case when code is died.
I also do not want extra exception handling and rethrowing it in my code.
Let compare:
my ( $result ) = capture { print "YES"; die; 1; }, my( $stdout, $stderr );
VS
use Try::Tiny;
my $saved_error;
my ( $stdout, $stderr, $result ) = capture { try { print "YES"; die; 1; } catch { $saved_error = $_; undef; } };
die $saved_error if $saved_error;
Second is crazy code in compare with first.
Also in case I sugeest to you. Module API is going to be more clear. Just one method VS three
from capture-tiny.
Certainly, at this point the API will not change.
In your second code example, the try/catch are pointless, as $saved_error
is the same error that would be thrown if you didn't use try/catch in the first place and you're not doing anything with $stdout
, $stderr
, or $result
anyway.
I don't understand what you think would be different with capture variables passed as arguments.
from capture-tiny.
I don't understand what you think would be different with capture variables passed as arguments.
#!/usr/bin/perl
sub capture1 {
my $result = 1;
$stdout = 'Some text printed to stdout';
die 'Enexpected exception';
return ( $stdout, $stderr, $result );
}
sub capture2 {
my $result = 1;
my $stdout = \$_[1];
$$stdout = 'Some text printed to stdout';
die 'Enexpected exception';
return ( $stdout, $stderr, $result );
}
my( $stdout, $stderr, $result );
eval {
# we need force scalar
($stdout, $stderr, $result) = capture1( scalar sub{ } );
};
print "EXAMPLE 1: $stdout, $stderr, $result\n";
eval {
# scalar context by nature
$result = capture2( sub{ }, $stdout, $stderr );
};
print "EXAMPLE 2: $stdout, $stderr, $result\n";
program OUTPUT is:
EXAMPLE 1: , ,
EXAMPLE 2: Some text printed to stdout, ,
See difference? =)
Certainly, at this point the API will not change.
I ask to extend API. Your capture_* you can leave forever or maybe in far future start long deprecation period.
In your second code example, the try/catch are pointless
Of course I want to do something with $stdout. And I will do.
As I showed before in example 'capture1'
In case of your API it is impossible to handle exception and catch $stdout.
This is more sensitive in web based applications where I need to know and analize what is already sent to STDOUT before exception occour.
from capture-tiny.
It's not documented, but $@
is preserved (as is $?
). So you can just do this:
my ($stdout, $stderr, $result) = capture { eval { print "some text"; die "fatal" } };
my $err = $@;
# $stdout contains "some text"
# $err contans "fatal at ..."
How is that?
from capture-tiny.
Related Issues (20)
- JSON::PP dependency HOT 3
- Typo in documentation
- Update ToDo
- Typo in documentation
- tests fail sporadically on a ubuntu vm with perl 5.18.2 HOT 4
- new develop prereq on 'English'? HOT 2
- tee_merged leaves cruft in /tmp HOT 4
- Capture::Tiny leaves temp files behind HOT 1
- STDERR PerlIO layers are not preserved
- stdin custom filehandle option
- Documentation should warn that this module should never be used in multiple threads in parallel
- capture exec leaves files in /tmp
- tee hangs when running sshutle in daemonized mode HOT 2
- tee hangs when ran across forks HOT 2
- should be able to use scalarref filehandles? HOT 1
- capture causes error in/from Unix.pm
- how to get output for failed, hanging commands? HOT 1
- Capture::Tiny::capture has increasingly long 'start' delay HOT 2
- Failure when used from a wxPerl GUI app on Windows
- Leaves STDERR in line buffered mode HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from capture-tiny.