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