1 package Perlbal
::Fields
;
6 # allow package to be called in command line
7 __PACKAGE__
->run(@ARGV) unless caller();
9 # should be the main method called, extra sub could be triggered from this point
11 my ( $package, @options ) = @_;
13 # unactivate fields if launch in command line
19 # hash with keys and undef val for each class
20 my $cache_for_class = {};
22 # replace fields::new method which uses Hash::Util::lock_ref_keys
23 # - it's a good idea to keep using the original fields::new during development stage
24 # - but during production we can avoid locking hash and wasting time doing this ( ~ 30 % )
28 no warnings
"redefine";
32 $class = ref $class if ref $class;
34 if ( !defined( $cache_for_class->{$class} ) ) {
36 my @keys = keys %{ $class . "::FIELDS" };
37 map { $h->{$_} = undef; } @keys;
38 $cache_for_class->{$class} = $h;
40 my %h = %{ $cache_for_class->{$class} };
42 return bless \
%h, $class;