blib/lib/Inline/Perl.pm untested

filter: Statementstmt 0.0% 0 / 38 Branchbran 0.0% 0 / 6 Conditioncond 0.0% 0 / 12 MC/DCmcdc 0.0% 0 / 7 Subroutinesub 0.0% 0 / 9 Podpod 0.0% 0 / 5 totaltotal 0.0% 0 / 77 CC 4 SCAR 16.4
CC
4
Cov
0%
build
12.0
validate
6.0
register
2.0
CRAP 5.2
1 package Inline::Perl;
2 $Inline::Perl::VERSION = '0.01';
3 @Inline::Perl::ISA = qw(Inline);
4  
5 use strict;
6  
7 use Inline ();
8 use Perl ();
9  
10 =head1 NAME
11  
12 Inline::Perl - Inline module for another Perl interpreter
13  
14 =head1 VERSION
15  
16 This document describes version 0.01 of Inline::Perl, released
17 December 24, 2004.
18  
19 =head1 SYNOPSIS
20  
21 use Inline Perl => q{
22 sub set_x { $::x = $_[0] }
23 sub get_x { $::x }
24 };
25  
26 set_x(1);
27 $::x = 2;
28 print get_x(); # 1
29  
30 =head1 DESCRIPTION
31  
32 This module allows you to add blocks of Perl code to your Perl scripts
33 and modules. This allows you to run them in another interperter, and
34 then examine the results.
35  
36 All user-defined procedures in the inlined Perl code will be available
37 as normal subroutines; global variables are not exported.
38  
39 Objects, classes and procedures may also be imported by passing them
40 as config parameters to C<use Inline>. See L<Inline> for details about
41 this syntax.
42  
43 For information about handling another Perl interperter, please see
44 the B<PerlInterp> distribution on CPAN.
45  
46 =cut
47  
48 # register for Inline
49 sub register {
50 return {
51 language => 'Perl',
52 aliases => ['perl'],
53 type => 'interpreted',
54 suffix => 'go',
55 };
56 }
57  
58 # check options
59 sub validate {
60 my $self = shift;
61 my $perl = $self->{perl} ||= Perl->new;
62  
63 while (@_ >= 2) {
64 my ($key, $value) = (shift, shift);
65 $perl->define($key, $value) if $key =~ /^\w/;
66 }
67 }
68  
69 sub build {
70 my $self = shift;
71  
72 # magic dance steps to a successful Inline compile...
73 my $path = "$self->{API}{install_lib}/auto/$self->{API}{modpname}";
74 my $obj = $self->{API}{location};
75 $self->mkpath($path) unless -d $path;
76 $self->mkpath($self->{API}{build_dir}) unless -d $self->{API}{build_dir};
77  
78 # touch my monkey
79 open(OBJECT, ">$obj") or die "Unable to open object file: $obj : $!";
80 close(OBJECT) or die "Unable to close object file: $obj : $!";
81 }
82  
83 # load the code into the interpreter
84 sub load {
85 my $self = shift;
86 my $code = $self->{API}{code};
87 my $pkg = $self->{API}{pkg} || 'main';
88 my $perl = $self->{perl} ||= Perl->new;
89  
90 $perl->eval($code);
91  
92 no strict 'refs';
93 foreach my $sym ($perl->eval(q[grep *{$::{$_}}{CODE}, keys %::])) {
94 *{"$pkg\::$sym"} = sub {
95 $perl->eval("$sym(".join(', ', map '"'.quotemeta($_).'"', @_).")");
96 };
97 }
98 }
99  
100 # no info implementation yet
101 sub info { }
102  
103 1;
104  
105 __END__