[svn:p5ee] r8030 - p5ee/trunk/App-Widget/lib/App

[email protected]
Newsgroups perl.cvs.p5ee
Message-ID <[email protected]>
Author: spadkins
Date: Thu Nov  9 09:40:40 2006
New Revision: 8030

Modified:
   p5ee/trunk/App-Widget/lib/App/Widget.pm

Log:
add format() method

Modified: p5ee/trunk/App-Widget/lib/App/Widget.pm
==============================================================================
--- p5ee/trunk/App-Widget/lib/App/Widget.pm	(original)
+++ p5ee/trunk/App-Widget/lib/App/Widget.pm	Thu Nov  9 09:40:40 2006
@@ -9,6 +9,8 @@
 use App::SessionObject;
 @ISA = ( "App::SessionObject" );
 
+use Date::Format;
+use Date::Parse;
 use strict;
 
 =head1 NAME
@@ -512,5 +514,39 @@
    $url;
 }
 
+sub format {
+    &App::sub_entry if ($App::trace);
+    my ($self, $value, $format_options) = @_;
+
+    my $formatted_value = $value;
+
+    if ($format_options->{scale_factor}) {
+        $formatted_value *= $format_options->{scale_factor};
+    }
+    if ($format_options->{format}) {
+        $formatted_value = sprintf($format_options->{format}, $value);
+    }
+    elsif ($format_options->{date_format}) {
+        if (defined $format_options->{date_suffix}) {
+            $formatted_value .= $format_options->{date_suffix};
+        }
+        $formatted_value = time2str($format_options->{date_format}, str2time($formatted_value));
+    }
+    elsif ($format_options->{labels}) {
+        $formatted_value = $format_options->{labels}{$value};
+        $formatted_value = $value if (!defined $formatted_value);
+    }
+    elsif ($format_options->{domain}) {
+        my $context = App->context();
+        my $value_domain = $context->value_domain($format_options->{domain});
+        my $labels = $value_domain->labels();
+        $formatted_value = $labels->{$value};
+        $formatted_value = $value if (!defined $formatted_value);
+    }
+
+    &App::sub_exit($formatted_value) if ($App::trace);
+    return($formatted_value);
+}
+
 1;
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.