1#!/usr/bin/env perl
2
3package Left;
4
5sub left { __PACKAGE__ }
6sub both { __PACKAGE__ }
7
8package Right;
9
10sub right { __PACKAGE__ }
11sub both { __PACKAGE__ }
12
13package main;
14
15use strict;
16use warnings;
17
18use Test::More tests => 32;
19
20{
21    use autobox SCALAR => [ qw(Left Right) ];
22
23    ok(42->autobox_class->isa('Left'), 'LR1: isa Left');
24    ok(42->autobox_class->isa('Right'), 'LR1: isa Right');
25
26    ok(42->autobox_class->can('left'), 'LR1: can left');
27    ok(42->autobox_class->can('both'), 'LR1: can both');
28    ok(42->autobox_class->can('right'), 'LR1: can right');
29
30    is(42->left, 'Left', 'LR1: left');
31    is(42->both, 'Left', 'LR1: both');
32    is(42->right, 'Right', 'LR1: right');
33}
34
35{
36    use autobox SCALAR => 'Left';
37    use autobox SCALAR => 'Right';
38
39    ok(42->autobox_class->isa('Left'), 'LR2: isa Left');
40    ok(42->autobox_class->isa('Right'), 'LR2: isa Right');
41
42    ok(42->autobox_class->can('left'), 'LR2: can left');
43    ok(42->autobox_class->can('both'), 'LR2: can both');
44    ok(42->autobox_class->can('right'), 'LR2: can right');
45
46    is(42->left, 'Left', 'LR2: left');
47    is(42->both, 'Left', 'LR2: both');
48    is(42->right, 'Right', 'LR2: right');
49}
50
51{
52    use autobox SCALAR => [ qw(Right Left) ];
53
54    ok(42->autobox_class->isa('Left'), 'RL1: isa Left');
55    ok(42->autobox_class->isa('Right'), 'RL1: isa Right');
56
57    ok(42->autobox_class->can('left'), 'RL1: can left');
58    ok(42->autobox_class->can('both'), 'RL1: can both');
59    ok(42->autobox_class->can('right'), 'RL1: can right');
60
61    is(42->left, 'Left', 'RL1: left');
62    is(42->both, 'Right', 'RL1: both');
63    is(42->right, 'Right', 'RL1: right');
64}
65
66{
67    use autobox SCALAR => 'Right';
68    use autobox SCALAR => 'Left';
69
70    ok(42->autobox_class->isa('Left'), 'RL2: isa Left');
71    ok(42->autobox_class->isa('Right'), 'RL2: isa Right');
72
73    ok(42->autobox_class->can('left'), 'RL2: can left');
74    ok(42->autobox_class->can('both'), 'RL2: can both');
75    ok(42->autobox_class->can('right'), 'RL2: can right');
76
77    is(42->left, 'Left', 'RL2: left');
78    is(42->both, 'Right', 'RL2: both');
79    is(42->right, 'Right', 'RL2: right');
80}
81