Mercurial > pub > Impl
comparison lib/IMPL/lang.pm @ 408:5c80e33f1218 ref20150831
added 'coarsen' function
| author | cin |
|---|---|
| date | Mon, 07 Sep 2015 01:35:25 +0300 |
| parents | c6e90e02dd17 |
| children | f7eeafbd33da |
comparison
equal
deleted
inserted
replaced
| 407:c6e90e02dd17 | 408:5c80e33f1218 |
|---|---|
| 4 | 4 |
| 5 use parent qw(Exporter); | 5 use parent qw(Exporter); |
| 6 use IMPL::_core::version; | 6 use IMPL::_core::version; |
| 7 use IMPL::clone qw(clone); | 7 use IMPL::clone qw(clone); |
| 8 use Scalar::Util qw(blessed); | 8 use Scalar::Util qw(blessed); |
| 9 use POSIX; | |
| 9 use Carp qw(carp); | 10 use Carp qw(carp); |
| 10 | 11 |
| 11 our @EXPORT = qw(&is &isclass &typeof); | 12 our @EXPORT = qw(&is &isclass &typeof &coarsen); |
| 12 our %EXPORT_TAGS = ( | 13 our %EXPORT_TAGS = ( |
| 13 base => [ | 14 base => [ |
| 14 qw( | 15 qw( |
| 15 &is | 16 &is |
| 16 &clone | 17 &clone |
| 132 my ( $name, $value ) = @_; | 133 my ( $name, $value ) = @_; |
| 133 my $class = caller; | 134 my $class = caller; |
| 134 $class->static_accessor( $name, $value ); | 135 $class->static_accessor( $name, $value ); |
| 135 } | 136 } |
| 136 | 137 |
| 138 sub coarsen { | |
| 139 my ( $value, $resolution ) = @_; | |
| 140 return $resolution ? ceil( $value / $resolution ) * $resolution : $value; | |
| 141 } | |
| 142 | |
| 137 sub equals { | 143 sub equals { |
| 138 if (defined $_[0]) { | 144 if (defined $_[0]) { |
| 139 return 0 if (not defined $_[1]); | 145 return 0 if (not defined $_[1]); |
| 140 | 146 |
| 141 return $_[0] == $_[1]; | 147 return $_[0] == $_[1]; |
