use lib 't/lib';
+use Test::Requires {
+ 'MooseX::StrictConstructor' => '0.01',
+};
+
use Test::MooseX::Compiler qw( save_class );
use Test::More 0.88;
);
my $compiled = $compiler->compile_class();
+
like(
$compiled,
qr/^\#\s*use Moose;\n/m,
);
my $compiled = $compiler->compile_class();
+
unlike(
$compiled,
qr/^\#\s*use Moose;\n/m,
);
}
+{
+ my $code = <<'EOF';
+package Test::Class3;
+
+use strict;
+use warnings;
+
+use Moose;
+use MooseX::StrictConstructor;
+
+sub foo { 42 }
+
+1;
+EOF
+
+ save_class( 'Test::Class1', $code );
+
+ my $compiler = MooseX::Compiler->new(
+ class => 'Test::Class1',
+ );
+
+ my $compiled = $compiler->compile_class();
+
+ like(
+ $compiled,
+ qr/^\#\s*use Moose;\n/m,
+ 'use Moose declaration is commented out in compiled code'
+ );
+
+ like(
+ $compiled,
+ qr/^\#\s*use MooseX::StrictConstructor;\n/m,
+ 'use MooseX::StrictConstructor declaration is commented out in compiled code'
+ );
+
+ unlike(
+ $compiled,
+ qr/^use Moose;\n/m,
+ 'original use Moose declaration is removed from compiled code'
+ );
+
+ unlike(
+ $compiled,
+ qr/^use MooseX::StrictConstructor;\n/m,
+ 'original use MooseX::StrictConstructor declaration is removed from compiled code'
+ );
+}
+
+{
+ my $code = <<'EOF';
+package Test::Class4;
+
+use strict;
+use warnings;
+
+use Moose;
+use MooseX::StrictConstructor 0.01;
+
+sub foo { 42 }
+
+1;
+EOF
+
+ save_class( 'Test::Class1', $code );
+
+ my $compiler = MooseX::Compiler->new(
+ class => 'Test::Class1',
+ );
+
+ my $compiled = $compiler->compile_class();
+
+ like(
+ $compiled,
+ qr/^\#\s*use Moose;\n/m,
+ 'use Moose declaration is commented out in compiled code'
+ );
+
+ unlike(
+ $compiled,
+ qr/^use Moose;\n/m,
+ 'original use Moose declaration is removed from compiled code'
+ );
+
+ unlike(
+ $compiled,
+ qr/^\#\s*use MooseX::StrictConstructor;\n/m,
+ 'use MooseX::StrictConstructor declaration is not commented out in compiled code'
+ );
+
+ like(
+ $compiled,
+ qr/^use\s+MooseX::StrictConstructor\s+0\.01\s+\(\)\s*;\n/m,
+ 'original use MooseX::StrictConstructor declaration is preserved, but () is added to prevent importing'
+ );
+}
+
done_testing();