Skip to content

Commit 4b10878

Browse files
JRaspasskhwilliamson
authored andcommitted
Modernise SelectSaver
- Move the version declaration into the package line. - Move the code above the POD and add an __END__ token. - Use v5.40 to get strict, warnings, and the module_true feature. - Use subroutine signatures and remove hand rolled arity croak.
1 parent a1813c5 commit 4b10878

File tree

1 file changed

+14
-23
lines changed

1 file changed

+14
-23
lines changed

lib/SelectSaver.pm

Lines changed: 14 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,18 @@
1-
package SelectSaver;
1+
package SelectSaver 1.03;
22

3-
our $VERSION = '1.02';
3+
use v5.40;
4+
5+
use Symbol 'qualify';
6+
7+
sub new ($class, $filehandle = undef) {
8+
my $fh = select;
9+
select qualify $filehandle, caller if defined $filehandle;
10+
return bless \$fh, $class;
11+
}
12+
13+
sub DESTROY ($self) { select $$self }
14+
15+
__END__
416
517
=head1 NAME
618
@@ -31,24 +43,3 @@ file handle remains unchanged.
3143
3244
When a C<SelectSaver> is destroyed, it re-selects the file handle
3345
that was selected when it was created.
34-
35-
=cut
36-
37-
require 5.000;
38-
use Carp;
39-
use Symbol;
40-
41-
sub new {
42-
@_ >= 1 && @_ <= 2 or croak 'usage: SelectSaver->new( [FILEHANDLE] )';
43-
my $fh = select;
44-
my $self = bless \$fh, $_[0];
45-
select qualify($_[1], caller) if @_ > 1;
46-
$self;
47-
}
48-
49-
sub DESTROY {
50-
my $self = $_[0];
51-
select $$self;
52-
}
53-
54-
1;

0 commit comments

Comments
 (0)