File Coverage

blib/lib/App/EvalServer/Language/Deparse.pm
Criterion Covered Total %
statement 11 23 47.8
branch 0 2 0.0
condition n/a
subroutine 5 6 83.3
pod 0 1 0.0
total 16 32 50.0


line stmt bran cond sub pod time code
1             package App::EvalServer::Language::Deparse;
2             BEGIN {
3 1     1   4880 $App::EvalServer::Language::Deparse::AUTHORITY = 'cpan:HINRIK';
4             }
5             BEGIN {
6 1     1   22 $App::EvalServer::Language::Deparse::VERSION = '0.08';
7             }
8              
9 1     1   8 use strict;
  1         3  
  1         42  
10 1     1   7 use warnings;
  1         2  
  1         28  
11 1     1   12 use B::Deparse;
  1         2  
  1         714  
12              
13             sub evaluate {
14 0     0 0   my ($package, $code) = @_;
15              
16 0           my $sub = eval "no strict; no warnings; sub{ $code\n }";
17              
18 0 0         print STDERR $@ if length($@);
19 0           my $dp = B::Deparse->new(qw<-p -q -x7>);
20 0           my $ret = $dp->coderef2text($sub);
21              
22 0           $ret =~ s/\{//;
23 0           $ret =~ s/package (?:\w+(?:::)?)+;//;
24 0           $ret =~ s/ no warnings;//;
25 0           $ret =~ s/\s+/ /g;
26 0           $ret =~ s/\s*\}\s*$//;
27 0           $ret =~ s/^\s*//;
28              
29 0           return $ret;
30             }
31              
32             1;
33              
34             =encoding utf8
35              
36             =head1 NAME
37              
38             App::EvalServer::Language::Deparse - Deparse Perl code with B::Deparse
39              
40             =head1 AUTHOR
41              
42             Hinrik Ern SigurEsson, hinrik.sig@gmail.com
43              
44             =head1 LICENSE AND COPYRIGHT
45              
46             Copyright 2010 Hinrik Ern SigurEsson
47              
48             This program is free software, you can redistribute it and/or modify
49             it under the same terms as Perl itself.
50              
51             =cut