1package Ball;    ## no critic (package)
2
3use strict;
4use warnings;
5
6use Inline CPP => config => classes => sub { join('::', split('__', shift)); },
7    force_build => 1, clean_after_build => 0;
8
9use Inline CPP => <<'EOCPP';
10  class MyClass {
11    private:
12      int a;
13    public:
14      MyClass() :a(5) {}
15      int fetch () { return a; }
16  };
17  class Foo__Bar__MyClass {
18    private:
19      int a;
20    public:
21      Foo__Bar__MyClass() :a(10) {}
22      int fetch () { return a; }
23  };
24  class Foo__Qux__MyClass {
25    private:
26      int a;
27    public:
28      Foo__Qux__MyClass() :a(20) {}
29      int fetch () { return a; }
30      int other_fetch () { Foo__Bar__MyClass mybar; return mybar.fetch(); }
31  };
32EOCPP
33
34package main;
35use Test::More;
36
37can_ok 'MyClass', 'new';
38my $m = new_ok 'MyClass';
39is ref($m), 'MyClass', 'Our "MyClass" is a "MyClass"';
40
41can_ok 'Foo::Bar::MyClass', 'new';
42my $fb = new_ok 'Foo::Bar::MyClass';
43is ref($fb), 'Foo::Bar::MyClass',
44  'Our "Foo__Bar__MyClass" is a "Foo::Bar::MyClass"';
45
46can_ok 'Foo::Qux::MyClass', 'new';
47my $fq = new_ok 'Foo::Qux::MyClass';
48is ref($fq), 'Foo::Qux::MyClass',
49  'Our "Foo__Qux__MyClass" is a "Foo::Qux::MyClass"';
50
51is $m->fetch,  5, 'Proper object method association from MyClass.';
52is $fb->fetch,  10, 'Proper object method association from Foo::Bar::MyClass.';
53is $fq->fetch, 20, 'Proper object method association from Foo::Qux::MyClass.';
54is $fq->other_fetch, 10,
55  'Proper cross-class method association from Foo::Qux::MyClass.';
56
57done_testing();
58