7 package Lexical::Types::Test::Str;
9 use overload '.' => \&_concat,
10 '""' => \&_interpolate,
15 my ($class, $buf) = @_;
16 $class = ref($class) || $class;
17 unless (defined $buf) {
19 } elsif ($buf->isa($class)) {
20 $buf = $buf->{buffer};
22 bless { buffer => $buf }, $class;
26 my ($self, $str, $r) = @_;
27 $self->new($r ? $str . $self->{buffer} : $self->{buffer} . $str);
30 sub _interpolate { shift->{buffer} }
34 my $bufa = ref($a) ? $a->{buffer} : $a;
35 my $bufb = ref($b) ? $b->{buffer} : $b;
36 my $res = $bufa cmp $bufb;
41 sub _typedscalar { __PACKAGE__->new() }
48 use Test::More tests => 2 * 6;
50 use Lexical::Types as => sub {
51 return 'Lexical::Types::Test::' . $_[0],
58 isa_ok $x, 'Lexical::Types::Test::Str', '$x';
59 is "$x", '', '$x contains the right thing';
62 isa_ok $x, 'Lexical::Types::Test::Str', '$x . "foo"';
63 is "$x", 'foo', '$x . "foo" contains the right thing';
66 isa_ok $x, 'Lexical::Types::Test::Str', '"bar" . $x';
67 is "$x", 'barfoo', '"bar" . $x contains the right thing';