| 1 | # | ||
| 2 | # Data::Shark::Util.pm | ||
| 3 | # | ||
| 4 | # Copyright (C) 2007 William Walz. All Rights Reserved | ||
| 5 | # This program is free software; you can redistribute it and/or | ||
| 6 | # modify it under the same terms as Perl itself. | ||
| 7 | # | ||
| 8 | # $Id: Util.pm 907 2006-05-19 17:39:37Z bill $ | ||
| 9 | # | ||
| 10 | |||
| 11 | package Data::Shark::Util; | ||
| 12 | |||
| 13 | use version; our $VERSION = qv('2.1'); | ||
| 14 | |||
| 15 | use strict; | ||
| 16 | use base qw( Exporter ); | ||
| 17 | |||
| 18 | our @EXPORT = qw( ); | ||
| 19 | our @EXPORT_OK = qw( mc commify my_money ); | ||
| 20 | our %EXPORT_TAGS = ( | ||
| 21 | ALL => [@EXPORT, @EXPORT_OK], | ||
| 22 | ); | ||
| 23 | |||
| 24 | # | ||
| 25 | # Module Functions | ||
| 26 | # | ||
| 27 | |||
| 28 | sub commify { | ||
| 29 | local $_ = shift; | ||
| 30 | 1 while s/^([-+]?\d+)(\d{3})/$1,$2/; | ||
| 31 | return $_; | ||
| 32 | } | ||
| 33 | |||
| 34 | sub my_money { | ||
| 35 | my ($a,$dash) = @_; | ||
| 36 | |||
| 37 | $a = 0 if !$a; | ||
| 38 | |||
| 39 | return '-' if !$a && $dash; | ||
| 40 | |||
| 41 | $a = sprintf("%0.2f", $a); | ||
| 42 | |||
| 43 | my $b = commify($a); | ||
| 44 | |||
| 45 | $a < 0 && do { | ||
| 46 | $b =~ s/-//g; | ||
| 47 | return '$(' . $b .')'; | ||
| 48 | }; | ||
| 49 | |||
| 50 | return '$' . $b; | ||
| 51 | } | ||
| 52 | |||
| 53 | sub mc { | ||
| 54 | # makes a string Mixed Case | ||
| 55 | my $str = lc shift; | ||
| 56 | $str =~ s/(\w+)/\u$1/g; | ||
| 57 | return $str; | ||
| 58 | } | ||
| 59 | |||
| 60 | 1; | ||
| 61 | __END__ |