in reply to Overriding CORE::GLOBAL::bless
This is tricky. I've found that using the subs pragma in the package space of the package in which you want to override an operator before you load the module normally seems to work:
use Test::More tests => 2; package CGI; use subs 'bless'; package main; my $called = 0; use CGI; sub CGI::bless { $called++; CORE::bless( $_[0], $_[1] ); }; my $foo = CGI->new(); is( $called, 1, 'bless() should call overridden version' ); isa_ok( $foo, 'CGI', 'which should return something that' );
|
|---|