144
|
0 |
1 |
unless eval qq[\n package UNIVERSAL;\n use Carp;\n use Data::Dumper;\n our \$AUTOLOAD;\n my %fields_storage = ();\n my %methods = ();\n my %counter;\n\n sub UNIVERSAL::AUTOLOAD {\n return undef if (caller(0) eq 'UNIVERSAL'); # To prevent recursive calls\n my (\$class, \$method) = (\$AUTOLOAD =~ /(.*)::([^:]+)/);\n return undef if (\$method eq 'DESTROY' or \$method eq 'unimport');\n {\n no strict;\n unless (\$fields_storage{\$class}) { # First time\n eval "require \$class;" or return Class::Hook->_error("\$class: \$! \$\@");\n delete \$INC{"\$class.pm"};\n \$class->import();\n %{\$fields_storage{\$class}} = %{"\${class}::"}; # Stores namespace\n }\n %{"\${class}::"} = %{\$fields_storage{\$class}};\n }\n my \@param = \@_;\n\t\t\t\t\t\tmy \$obj = \$_[0] if (ref(\$_[0]) eq \$class);\n shift \@param if (\$_[0] eq \$class or ref(\$_[0]) eq \$class); # method call\n \$counter{\$AUTOLOAD} ||= 0;\n my \@before_params = { class => \$class,\n method => \$method,\n counter => \$counter{\$AUTOLOAD}++,\n param => \\\@param,\n };\n unshift \@before_params, \$Class::Hook::param_before if (defined \$Class::Hook::param_before);\n &\$Class::Hook::before( \@before_params );\n my \$t0 = [Time::HiRes::gettimeofday()];\n no strict;\n my \@rtn;\n if (\$obj) {\n \t\@rtn = \$obj->\$method(\@param) || ();\n }\n else {\n \t\@rtn = \$class->\$method(\@param) || ();\n }\n my \@after_params = { class => \$class,\n method => \$method,\n counter => \$counter{\$AUTOLOAD},\n param => \\\@param,\n 'return' => wantarray ? \\\@rtn : \$rtn[0],\n duration => Time::HiRes::tv_interval(\$t0, [Time::HiRes::gettimeofday()]) };\n unshift \@after_params, \$Class::Hook::param_after if (defined \$Class::Hook::param_after);\n &\$Class::Hook::after( \@after_params );\n %{"\${class}::"} = (); # Clean namespace to force calls to %UNIVERSAL::\n return wantarray ? \@rtn : \$rtn[0];\n }\n 1;\n ] |