Mercurial > pub > Impl
diff Lib/IMPL/lang.pm @ 177:df71a307ef9b
new constructor syntax
author | sourcer |
---|---|
date | Wed, 12 Oct 2011 00:04:13 +0300 |
parents | 74c27daf2e7b |
children | 658a80d19d33 |
line wrap: on
line diff
--- a/Lib/IMPL/lang.pm Wed Oct 05 16:23:45 2011 +0400 +++ b/Lib/IMPL/lang.pm Wed Oct 12 00:04:13 2011 +0300 @@ -38,6 +38,8 @@ &property &static &property + &ctor + &base ) ], compare => [ @@ -117,6 +119,24 @@ $class->static_accessor( $name, $value ); } +sub ctor(&;$) { + my ( $code, $base ) = @_; + no strict 'refs'; + my $class = caller; + + if ($code) { + *{"${class}::CTOR"} = $code; + } + + if (ref $base eq 'HASH') { + %{"${class}::CTOR"} = %$base; + } +} + +sub base($) { + return shift; +} + sub equals { if (defined $_[0]) { return 0 if (not defined $_[1]);