}
{
+ package OverloadStr;
+ use overload
+ q{""} => sub { ${ $_[0] } },
+ fallback => 1;
+
+ sub new {
+ my $class = shift;
+ my $str = shift;
+ return bless \$str, $class;
+ }
+}
+
+{
run_tests(build_class);
run_tests( build_class( lazy => 1, default => sub { [ 42, 84 ] } ) );
run_tests( build_class( trigger => sub { } ) );
'join returns expected result when joining with empty string'
);
+ is(
+ $obj->join( OverloadStr->new(q{}) ), '1234',
+ 'join returns expected result when joining with empty string'
+ );
+
like( exception { $obj->join }, qr/Cannot call join without at least 1 argument/, 'throws an error when passing no arguments to join' );
like( exception { $obj->join( '-', 2 ) }, qr/Cannot call join with more than 1 argument/, 'throws an error when passing two arguments to join' );
$class;
}
+{
+ my ( $class, $handles ) = build_class( isa => 'ArrayRef' );
+ my $obj = $class->new;
+ with_immutable {
+ is(
+ exception { $obj->accessor( 0, undef ) },
+ undef,
+ 'can use accessor to set value to undef'
+ );
+ is(
+ exception { $obj->accessor_curried_1(undef) },
+ undef,
+ 'can use curried accessor to set value to undef'
+ );
+ }
+ $class;
+}
+
done_testing;