Mercurial > pub > Impl
comparison Lib/IMPL/lang.pm @ 178:658a80d19d33
new constructor syntax
author | sourcer |
---|---|
date | Wed, 12 Oct 2011 00:06:07 +0300 |
parents | df71a307ef9b |
children | 47dac58691ee |
comparison
equal
deleted
inserted
replaced
177:df71a307ef9b | 178:658a80d19d33 |
---|---|
37 &virtual | 37 &virtual |
38 &property | 38 &property |
39 &static | 39 &static |
40 &property | 40 &property |
41 &ctor | 41 &ctor |
42 &base | |
43 ) | 42 ) |
44 ], | 43 ], |
45 compare => [ | 44 compare => [ |
46 qw( | 45 qw( |
47 &equals | 46 &equals |
118 my $class = caller; | 117 my $class = caller; |
119 $class->static_accessor( $name, $value ); | 118 $class->static_accessor( $name, $value ); |
120 } | 119 } |
121 | 120 |
122 sub ctor(&;$) { | 121 sub ctor(&;$) { |
123 my ( $code, $base ) = @_; | 122 my ( $code, %base ) = @_; |
124 no strict 'refs'; | 123 no strict 'refs'; |
125 my $class = caller; | 124 my $class = caller; |
126 | 125 |
127 if ($code) { | 126 if ($code) { |
128 *{"${class}::CTOR"} = $code; | 127 *{"${class}::CTOR"} = $code; |
129 } | 128 } |
130 | 129 |
131 if (ref $base eq 'HASH') { | 130 if (%base) { |
132 %{"${class}::CTOR"} = %$base; | 131 %{"${class}::CTOR"} = %base; |
133 } | 132 } |
134 } | |
135 | |
136 sub base($) { | |
137 return shift; | |
138 } | 133 } |
139 | 134 |
140 sub equals { | 135 sub equals { |
141 if (defined $_[0]) { | 136 if (defined $_[0]) { |
142 return 0 if (not defined $_[1]); | 137 return 0 if (not defined $_[1]); |