initial commit
[gitmo/MooseX-Compiler.git] / t / lib / Test / MooseX / Compiler.pm
1 package Test::MooseX::Compiler;
2
3 use strict;
4 use warnings;
5 use autodie;
6
7 use Exporter qw( import );
8 use File::Temp qw( tempdir );
9 use Module::Runtime qw( module_notional_filename );
10 use Path::Class qw( dir );
11
12 our @EXPORT_OK = qw(
13     save_class
14 );
15
16 my $Dir = dir( tempdir( CLEANUP => 1 ) );
17
18 sub save_class {
19     my $class = shift;
20     my $code  = shift;
21
22     {
23         local $@;
24         eval $code;
25         die $@ if $@;
26     }
27
28     my $pm_file = module_notional_filename($class);
29     my $path    = $Dir->file($pm_file);
30     $path->dir()->mkpath( 0, 0755 );
31
32     open my $fh, '>', $path;
33     print {$fh} $code;
34     close $fh;
35
36     $INC{$pm_file} = $path;
37
38     return $pm_file;
39 }
40
41 1;