- Depend on B::Hooks::OP::Check version 0.19, which fixes a serious bug in
how it interacts with other modules that hook ops.
+ - Initialize immediately upon loading the module, so that "was Devel::Declare
+ loaded soon enough" errors in string eval can be fixed by loading the
+ module earlier without having to also actually use the module earlier.
- Adjust toke_scan_str logic to always show a positive effective length of
string source.
- Return undef from toke_scan_str if string was unterminated.
#endif /* !DD_CONST_VIA_RV2CV */
-static int initialized = 0;
-
-MODULE = Devel::Declare PACKAGE = Devel::Declare
-
-PROTOTYPES: DISABLE
-
-void
-setup()
- CODE:
- if (!initialized++) {
+STATIC void dd_initialize(pTHX) {
+ static int initialized = 0;
+ if (!initialized) {
+ initialized = 1;
#if DD_GROW_VIA_BLOCKHOOK
static BHK bhk;
#if PERL_VERSION_GE(5,13,6)
hook_op_check(OP_CONST, dd_ck_const, NULL);
#endif /* !DD_CONST_VIA_RV2CV */
}
- filter_add(dd_filter_realloc, NULL);
+}
+
+MODULE = Devel::Declare PACKAGE = Devel::Declare
+
+PROTOTYPES: DISABLE
+
+void
+initialize()
+ CODE:
+ dd_initialize(aTHX);
+
+void
+setup()
+ CODE:
+ dd_initialize(aTHX);
+ filter_add(dd_filter_realloc, NULL);
char*
get_linestr()
@ISA = ();
+initialize();
+
sub import {
my ($class, %args) = @_;
my $target = caller;
--- /dev/null
+use strict;
+use warnings;
+use Test::More tests => 2;
+
+use Devel::Declare;
+eval q[
+ BEGIN {
+ *class = sub (&) { $_[0]->() };
+ Devel::Declare->setup_for(__PACKAGE__, {
+ class => {
+ const => sub {
+ my ($kw, $off) = @_;
+ $off += Devel::Declare::toke_move_past_token($off);
+ $off += Devel::Declare::toke_skipspace($off);
+ die unless substr(Devel::Declare::get_linestr(), $off, 1) eq '{';
+ my $l = Devel::Declare::get_linestr();
+ substr $l, $off + 1, 0, 'pass q[injected];' . (';' x 1000);
+ Devel::Declare::set_linestr($l);
+ },
+ },
+ });
+ }
+ class {};
+];
+is $@, "";
+
+1;