1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152
|
use strict;
use warnings;
use FindBin;
use lib "$FindBin::Bin/../";
use Test::More;
use t::Util;
test('if (eval)', <<'END', {}, {'Test::More' => 0});
if ( eval "require 'Test/More.pm';" ) { }
END
test('eval()', <<'END', {}, {'Test::More' => 0});
eval('use Test::More');
END
test('eval{"string"}', <<'END', {}, {});
eval{'use Test::More'};
END
test('eval heredoc', <<'END', {}, {'Test::More' => 0});
eval <<'EOF';
require Test::More;
EOF
END
# adapted from NWELLNHOF/Lucy-0.6.1/buildlib/Lucy/Build/Binding/Misc.pm
test('eval $VARIABLE (should not rescan the inside of the following heredoc)', <<'END', {strict => 0, warnings => 0}, {});
package Lucy::Build::Binding::Misc;
use strict;
use warnings;
our $VERSION = '0.006001';
$VERSION = eval $VERSION;
# (snip)
sub bind_simple {
my @hand_rolled = qw( Add_Doc );
$pod_spec->set_synopsis($synopsis);
$pod_spec->add_constructor( sample => $constructor );
# Override is necessary because there's no standard way to explain
# hash/hashref across multiple host languages.
$pod_spec->add_method(
method => 'Add_Doc',
alias => 'add_doc',
pod => $add_doc_pod,
);
my $xs_code = <<'END_XS_CODE';
MODULE = Lucy PACKAGE = Lucy::Simple
void
add_doc(self, doc_sv)
lucy_Simple *self;
SV *doc_sv;
PPCODE:
{
lucy_Doc *doc = NULL;
// Either get a Doc or use the stock doc.
if (sv_isobject(doc_sv)
&& sv_derived_from(doc_sv, "Lucy::Document::Doc")
) {
IV tmp = SvIV(SvRV(doc_sv));
doc = INT2PTR(lucy_Doc*, tmp);
}
else if (XSBind_sv_defined(aTHX_ doc_sv) && SvROK(doc_sv)) {
HV *maybe_fields = (HV*)SvRV(doc_sv);
if (SvTYPE((SV*)maybe_fields) == SVt_PVHV) {
lucy_Indexer *indexer = LUCY_Simple_Get_Indexer(self);
doc = LUCY_Indexer_Get_Stock_Doc(indexer);
LUCY_Doc_Set_Fields(doc, maybe_fields);
}
}
if (!doc) {
THROW(CFISH_ERR, "Need either a hashref or a %o",
CFISH_Class_Get_Name(LUCY_DOC));
}
LUCY_Simple_Add_Doc(self, doc);
}
END_XS_CODE
my $binding = Clownfish::CFC::Binding::Perl::Class->new(
parcel => "Lucy",
class_name => "Lucy::Simple",
);
$binding->exclude_method($_) for @hand_rolled;
$binding->append_xs($xs_code);
$binding->set_pod_spec($pod_spec);
Clownfish::CFC::Binding::Perl::Class->register($binding);
}
END
test('eval()', <<'END', {}, {'GD::Simple' => 0});
my $load_this_package=eval("require GD::Simple;");
END
# TONYC/Imager-1.006/Imager.pm
test('eval ()', <<'END', {}, {'Affix::Infix2Postfix' => 0});
sub transform {
my $self=shift;
my %opts=@_;
my (@op,@ropx,@ropy,$iop,$or,@parm,$expr,@xt,@yt,@pt,$numre);
# print Dumper(\%opts);
# xopcopdes
$self->_valid_image("transform")
or return;
if ( $opts{'xexpr'} and $opts{'yexpr'} ) {
if (!$I2P) {
{
local @INC = @INC;
pop @INC if $INC[-1] eq '.';
eval ("use Affix::Infix2Postfix;");
}
}
}
}
END
test('use after eval $VERSION', <<'END', {strict => 0, Carp => 0});
use strict;
our $VERSION = '7.24';
$VERSION = eval $VERSION;
use Carp;
END
test('eval (shortcut)', <<'END', {strict => 0, Carp => 0});
use strict;
our $VERSION = '7.24';
$VERSION = eval($VERSION);
use Carp;
END
test('eval {shortcut}', <<'END', {strict => 0, Carp => 0});
use strict;
our $VERSION = '7.24';
$VERSION = eval{$VERSION};
use Carp;
END
done_testing;
|