Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Github issue #5 - _coderef() should properly detect non-coderefs
- Loading branch information
Showing
3 changed files
with
91 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
#!/usr/bin/perl | ||
|
||
# | ||
# Copyright (C) 2018 Joelle Maslak | ||
# All Rights Reserved - See License | ||
# | ||
|
||
use strict; | ||
use warnings; | ||
use autodie; | ||
|
||
use v5.10; | ||
|
||
use Carp; | ||
|
||
use Test2::V0; | ||
|
||
use File::ByLine; | ||
|
||
package overloadcode { | ||
use overload '&{}' => \&mysub; | ||
|
||
sub new { | ||
my $self = {}; | ||
bless $self; | ||
return $self; | ||
} | ||
|
||
sub mysub { | ||
return sub { return 1 }; | ||
} | ||
}; | ||
|
||
package overloadarray { | ||
use overload '@{}' => \&myarr; | ||
|
||
sub new { | ||
my $self = {}; | ||
bless $self; | ||
return $self; | ||
} | ||
|
||
sub myarr { | ||
return []; | ||
} | ||
}; | ||
|
||
my $arraylike = overloadarray->new(); | ||
my $codelike = overloadcode->new(); | ||
|
||
my $byline = File::ByLine->new(); | ||
|
||
ok dies { $byline->header_handler("not code") }, "String dies"; | ||
ok dies { $byline->header_handler( [] ) }, "Arrayref dies"; | ||
|
||
ok lives { $byline->header_handler($codelike) }, "Overloaded coderef lives"; | ||
ok dies { $byline->header_handler($arraylike) }, "Overloaded arrayref dies"; | ||
|
||
done_testing(); | ||
|