From e77b97e0b4f6f11f2d3dfab5c3dbe612e98483f6 Mon Sep 17 00:00:00 2001 From: Toddr Bot Date: Mon, 6 Apr 2026 00:00:40 +0000 Subject: [PATCH] fix: use Carp for error messages to report caller location MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Module errors now point to the caller's code instead of IO::Stty internals. die→croak for the no-args error, warn→carp for invalid parameters, unknown baud rates, and unrecognized char values. Co-Authored-By: Claude Opus 4.6 --- lib/IO/Stty.pm | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/lib/IO/Stty.pm b/lib/IO/Stty.pm index af61fb0..8842d45 100644 --- a/lib/IO/Stty.pm +++ b/lib/IO/Stty.pm @@ -3,6 +3,7 @@ package IO::Stty; use strict; use warnings; +use Carp; use POSIX; our $VERSION = '0.08'; @@ -475,7 +476,7 @@ sub _parse_char_value { return ord($val); } - warn "IO::Stty: unrecognized character value '$val'\n"; + carp "IO::Stty: unrecognized character value '$val'"; return 0; } @@ -500,7 +501,7 @@ From comments: sub stty { my $tty_handle = shift; # This should be a \*HANDLE - @_ or die("No parameters passed to stty"); + @_ or croak("No parameters passed to stty"); # Notice fileno() instead of handle->fileno(). I want it to work with # normal fhs. @@ -513,7 +514,7 @@ sub stty { # make a terminal object. my ($termios) = POSIX::Termios->new(); unless ( $termios->getattr($file_num) ) { - warn "Couldn't get terminal parameters for '$tty_name', file num ($file_num)"; + carp "Couldn't get terminal parameters for '$tty_name', file num ($file_num)"; return undef; } my ($c_cflag) = $termios->getcflag; @@ -771,20 +772,20 @@ sub stty { # Speed? if ( $_ eq 'ospeed' ) { my $rate = shift(@parameters); - exists $BAUD_RATES{$rate} or warn "IO::Stty::stty: unknown baud rate '$rate'\n"; + exists $BAUD_RATES{$rate} or carp "IO::Stty: unknown baud rate '$rate'"; $ospeed = $BAUD_RATES{$rate} if exists $BAUD_RATES{$rate}; next; } if ( $_ eq 'ispeed' ) { my $rate = shift(@parameters); - exists $BAUD_RATES{$rate} or warn "IO::Stty::stty: unknown baud rate '$rate'\n"; + exists $BAUD_RATES{$rate} or carp "IO::Stty: unknown baud rate '$rate'"; $ispeed = $BAUD_RATES{$rate} if exists $BAUD_RATES{$rate}; next; } # Default.. parameter hasn't matched anything # print "char:".sprintf("%lo",ord($_))."\n"; - warn "IO::Stty::stty passed invalid parameter '$_'\n"; + carp "IO::Stty: invalid parameter '$_'"; } # What a pain in the ass! Ok.. let's write the crap back.