Skip to content

Commit

Permalink
Merge pull request #20 from wbraswell/wbraswell-master
Browse files Browse the repository at this point in the history
Namespace Hack, Automatic CLASSES Config Option, Mixed Subs & Methods
  • Loading branch information
daoswald committed Aug 21, 2014
2 parents 139cc07 + e07bfee commit 43d0f08
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 19 deletions.
7 changes: 2 additions & 5 deletions lib/Inline/CPP.pm
Expand Up @@ -335,11 +335,8 @@ sub xs_bindings {
elsif ($ref_classes_override eq 'CODE')
{
# Override both package and class names
(my $class_auto, my $pkg_auto)
= &{$o->{API}{classes_override}}($class);
if ($pkg_auto eq '') { $pkg = 'main'; }
else { $pkg = $pkg_auto; }
$proper_pkg = $pkg . '::' . $class_auto;
$proper_pkg = &{$o->{API}{classes_override}}($class);
if ($proper_pkg eq '') { $proper_pkg = 'main'; }
}
}
else { # Do not override package or class names
Expand Down
13 changes: 6 additions & 7 deletions lib/Inline/CPP.pod
Expand Up @@ -345,7 +345,7 @@ Specifies extra compiler flags. Corresponds to the MakeMaker option.
classes => sub {
my $cpp_class = shift;
...
return($perl_class, $perl_namespace);
return($perl_package);
};

Override C++ class name.
Expand All @@ -370,11 +370,9 @@ C<namespace> config option to exercise full control over class and package
naming.

When a code reference is provided, it must accept as its sole argument the C++
class name, and return a list containing the generated Perl class name and Perl
namespace. The Perl namespace is joined to the Perl class name using the '::'
double-colon scope token, and this is used as the Perl package name. When a
code reference is provided for the C<classes> config option, the value of the
C<namespace> config option is ignored.
class name, and return a single string value containing the generated Perl
package name. When a code reference is provided for the C<classes> config
option, the value of the C<namespace> config option is ignored.

The hash reference may be considered a manual mapping method, and the code
reference an automatic mapping method.
Expand Down Expand Up @@ -455,11 +453,12 @@ more complex codebases. This example automates the mapping of the '__' double-
underscore to the '::' double-colon scope token.

use Inline CPP => config =>
classes => sub { @_ = split('__', shift); (pop, join('::', @_)); };
classes => sub { join('::', split('__', shift)); };

For more information, please see the runnable examples:
C<t/classes/07conflict_avoid.t>
C<t/classes/08auto.t>
C<t/classes/09auto_mixed.t>

=head2 filters

Expand Down
6 changes: 1 addition & 5 deletions t/classes/08auto.t
Expand Up @@ -3,11 +3,7 @@ package Ball; ## no critic (package)
use strict;
use warnings;

use Inline CPP => config =>
classes => sub {
@_ = split('__', shift);
( pop, join( '::', @_ ) );
};
use Inline CPP => config => classes => sub { join('::', split('__', shift)); };

use Inline CPP => <<'EOCPP';
class MyClass {
Expand Down
4 changes: 2 additions & 2 deletions t/classes/09auto_mixed.t
Expand Up @@ -2,8 +2,8 @@ use strict;
use warnings;
use Test::More tests => 5;

use Inline (CPP => 'DATA', classes => sub { @_ = split( '__', shift ); ( pop, join( '::', @_ ) ); } ); # FAILURE
#use Inline (CPP => 'DATA', classes => { 'Inline__Test__Inline_CPP_Debug' => 'Inline::Test::Inline_CPP_Debug'} ); # SUCCESS
use Inline (CPP => 'DATA', classes => sub { join('::', split('__', shift)); } ); # AUTOMATIC
#use Inline (CPP => 'DATA', classes => { 'Inline__Test__Inline_CPP_Debug' => 'Inline::Test::Inline_CPP_Debug'} ); # MANUAL

can_ok 'Inline::Test::Inline_CPP_Debug', 'new';
my $my_object = new_ok 'Inline::Test::Inline_CPP_Debug';
Expand Down

0 comments on commit 43d0f08

Please sign in to comment.