我想这取决于背景.
&func呼叫时被重用我有这个代码,我eval在第1004行遇到意外的电话:
sub save_context {
@DB::context = ( \@_, (caller 2)[8..10], $@, $_ ); # line 1004
print_state "\nTRAPPED IN ", "\n\n" if _ddd;
DB::state( 'inDB', 1 );
}
Run Code Online (Sandbox Code Playgroud)
这个堆栈跟踪:
DB /x/local/lib/perl5/Devel/DebugHooks.pm 1419 DB::orig_frames
DB /x/local/lib/perl5/Devel/DebugHooks.pm 1460 DB::push_frame
DB /x/local/lib/perl5/Devel/DebugHooks.pm 1004 DB::__ANON__[/x/local/lib/perl5/Devel/DebugHooks.pm:1460]
DB /x/local/lib/perl5/Devel/DebugHooks.pm 1004 (eval)
DB /x/local/lib/perl5/Devel/DebugHooks.pm 1251 DB::save_context
DB /x/local/lib/perl5/Devel/DebugHooks.pm 1288 DB::DB_my 1
MyApp::Controller::User /x/lib/MyApp/Controller/User.pm 41 DB::DB 1
Mojolicious /x/local/lib/perl5/Mojolicious.pm 133 MyApp::Controller::User::list
Mojolicious::Plugins /x/local/lib/perl5/Mojolicious/Plugins.pm 15 Mojolicious::__ANON__[/x/local/lib/perl5/Mojolicious.pm:133]
...
Run Code Online (Sandbox Code Playgroud)
从我的日志文件中我可以看到DBIx::Class::DESTROYsub被调用:
DB::sub DB::state: l:1 d:0 s:5 t:0 /x/local/lib/perl5/Devel/DebugHooks.pm:1004 --> DBIx::Class::DESTROY
Run Code Online (Sandbox Code Playgroud)
为什么对象破坏被推迟?我想这与@_某种方式有关
任何建议都赞赏这可能会触发对象破坏
在&func没有参数列表的调用中,不仅@_重用元素,还重用了整个元素@_.
sub main {
print "main: @_ is ", \@_, "\n";
func(@_); # Values from @_ are copied into new @_. @_ after call: 1 2 3
&func; # Origin @_ is passed down. So @_ after call: 2 3
}
sub func {
print "func: @_ is ", \@_, "\n";
shift @_; # Here @_ is modified. Pay attention what values @_ left after call
}
main(1,2,3); # @_ will be initialized by: 1 2 3
Run Code Online (Sandbox Code Playgroud)
典型输出:
main: @_ is ARRAY(0xfc5958)
@_ initial: 1 2 3
func: @_ is ARRAY(0xfc5a00)
@_ after func(): 1 2 3
func: @_ is ARRAY(0xfc5958)
@_ after &func: 2 3
Run Code Online (Sandbox Code Playgroud)
从去main到&func呼叫,@_没有本地化,复制或以任何方式改变.从呼叫中改变@_内部会影响呼叫者,但是不会从呼叫中改变呼叫.func&func@_func()
| 归档时间: |
|
| 查看次数: |
117 次 |
| 最近记录: |