Mercurial > pub > Impl
diff Lib/IMPL/Class/Meta.pm @ 194:4d0e1962161c
Replaced tabs with spaces
IMPL::Web::View - fixed document model, new features (control classes, document constructor parameters)
author | cin |
---|---|
date | Tue, 10 Apr 2012 20:08:29 +0400 |
parents | d1676be8afcc |
children | a8db61d0ed33 |
line wrap: on
line diff
--- a/Lib/IMPL/Class/Meta.pm Tue Apr 10 08:13:22 2012 +0400 +++ b/Lib/IMPL/Class/Meta.pm Tue Apr 10 20:08:29 2012 +0400 @@ -36,59 +36,59 @@ } sub class_data { - my $class = shift; - $class = ref $class || $class; - - if (@_ > 1) { - my ($name,$value) = @_; - return $class_data{$class}{$name} = $value; - } else { - my ($name) = @_; - - if( exists $class_data{$class}{$name} ) { - $class_data{$class}{$name}; - } else { - if ( my $value = $class->_find_class_data($name) ) { - $class_data{$class}{$name} = clone($value); - } else { - undef; - } - } - } + my $class = shift; + $class = ref $class || $class; + + if (@_ > 1) { + my ($name,$value) = @_; + return $class_data{$class}{$name} = $value; + } else { + my ($name) = @_; + + if( exists $class_data{$class}{$name} ) { + $class_data{$class}{$name}; + } else { + if ( my $value = $class->_find_class_data($name) ) { + $class_data{$class}{$name} = clone($value); + } else { + undef; + } + } + } } sub static_accessor { - my ($class,$name,$value) = @_; - $class = ref $class || $class; - - no strict 'refs'; - - *{"${class}::${name}"} = sub { - if (@_ > 1) { - my $self = shift; - $self = ref $self || $self; - - if ($class ne $self) { - $self->static_accessor( $name => $_[0]); # define own class data - } else { - $value = $_[0]; - } - } else { - $value; - } - }; - $value + my ($class,$name,$value) = @_; + $class = ref $class || $class; + + no strict 'refs'; + + *{"${class}::${name}"} = sub { + if (@_ > 1) { + my $self = shift; + $self = ref $self || $self; + + if ($class ne $self) { + $self->static_accessor( $name => $_[0]); # define own class data + } else { + $value = $_[0]; + } + } else { + $value; + } + }; + $value }; sub _find_class_data { - my ($class,$name) = @_; - - no strict 'refs'; - - exists $class_data{$_}{$name} and return $class_data{$_}{$name} foreach @{"${class}::ISA"}; - - my $val; - $val = $_->can('_find_class_data') ? $_->_find_class_data($name) : undef and return $val foreach @{"${class}::ISA"}; + my ($class,$name) = @_; + + no strict 'refs'; + + exists $class_data{$_}{$name} and return $class_data{$_}{$name} foreach @{"${class}::ISA"}; + + my $val; + $val = $_->can('_find_class_data') ? $_->_find_class_data($name) : undef and return $val foreach @{"${class}::ISA"}; } 1; @@ -113,7 +113,7 @@ __PACKAGE__->PassThroughArgs; BEGIN { - public property name => prop_get | owner_set; + public property name => prop_get | owner_set; } package InfoExMeta; @@ -122,7 +122,7 @@ __PACKAGE__->PassThroughArgs; BEGIN { - public property description => prop_all; + public property description => prop_all; } package Foo; @@ -179,18 +179,18 @@ =begin code my @info = Foo->get_meta( - 'InfoMeta', - sub { ref $_ eq 'InfoMeta'}, # exclude subclasses ('InfoExMeta') - 1 # deep search + 'InfoMeta', + sub { ref $_ eq 'InfoMeta'}, # exclude subclasses ('InfoExMeta') + 1 # deep search ); my @info = Foo->get_meta( - 'InfoMeta', - sub { - my $item = shift; - ref $item eq 'InfoMeta' # exclude subclasses ('InfoExMeta') - }, - 1 # deep search + 'InfoMeta', + sub { + my $item = shift; + ref $item eq 'InfoMeta' # exclude subclasses ('InfoExMeta') + }, + 1 # deep search ); =end code @@ -220,9 +220,9 @@ __PACKAGE__->class_data( info => { version => 1 } ); # will be default for all subclasses sub say_version { - my ($self) = @_; - - print $self->class_data('info')->{version}; + my ($self) = @_; + + print $self->class_data('info')->{version}; } package Bar;