cvsuser 02/04/05 14:05:00
Modified: P5EEx/Blue/P5EEx/Blue Widget.pm
Log:
moved methods around for better documentation
Revision Changes Path
1.13 +144 -140 p5ee/P5EEx/Blue/P5EEx/Blue/Widget.pm
Index: Widget.pm
===================================================================
RCS file: /cvs/public/p5ee/P5EEx/Blue/P5EEx/Blue/Widget.pm,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -w -r1.12 -r1.13
--- Widget.pm 28 Mar 2002 16:18:15 -0000 1.12
+++ Widget.pm 5 Apr 2002 22:05:00 -0000 1.13
@@ -1,6 +1,6 @@
#############################################################################
-## $Id: Widget.pm,v 1.12 2002/03/28 16:18:15 spadkins Exp $
+## $Id: Widget.pm,v 1.13 2002/04/05 22:05:00 spadkins Exp $
#############################################################################
package P5EEx::Blue::Widget;
@@ -114,10 +114,6 @@
* Throws: P5EEx::Blue::Exception::Widget
* Since: 0.01
-=head2 Class Design
-
-...
-
=cut
#############################################################################
@@ -201,60 +197,6 @@
=cut
#############################################################################
-# PROTECTED METHODS
-#############################################################################
-
-=head1 Protected Methods:
-
-=cut
-
-#############################################################################
-# Method: service_type()
-#############################################################################
-
-=head2 service_type()
-
-Returns 'Widget';
-
- * Signature: $service_type = P5EEx::Blue::Widget->service_type();
- * Param: void
- * Return: $service_type string
- * Since: 0.01
-
- $service_type = $widget->service_type();
-
-=cut
-
-sub service_type () { 'Widget'; }
-
-#############################################################################
-# Method: absorbable_attribs()
-#############################################################################
-
-=head2 absorbable_attribs()
-
-Returns a list of attributes which a service of this type would like to
-absorb from its container service.
-This is a *static* method.
-It doesn't require an instance of the class to call it.
-
- * Signature: $attribs = P5EEx::Blue::Service->absorbable_attribs()
- * Param: void
- * Return: $attribs []
- * Throws: P5EEx::Blue::Exception
- * Since: 0.01
-
- $attribs = $widget->absorbable_attribs();
- @attribs = @{$widget->absorbable_attribs()};
-
-=cut
-
-sub absorbable_attribs {
- # for the general widget, there are only a few universal absorbable attributes
- [ "lang", "dict" ];
-}
-
-#############################################################################
# Method: handle_event()
#############################################################################
@@ -508,87 +450,6 @@
}
#############################################################################
-# Method: format()
-#############################################################################
-
-=head2 format()
-
- * Signature: $formatted_value = $self->format($value, $type, $format);
- * Param: $value scalar
- * Param: $type string
- * Param: $format string
- * Return: $formatted_value string
- * Throws: P5EEx::Blue::Exception
- * Since: 0.01
-
- $formatted_value = $widget->format("20020127","date","%Y-%m-%d");
- $formatted_value = $widget->format("27-Jan-02","date","%Y-%m-%d");
- $formatted_value = $widget->format("01/27/2002","date","%Y-%m-%d");
- $formatted_value = P5EEx::Blue::Widget->format("01/27/2002","date","%Y-%m-%d");
-
-A static method.
-
-=cut
-
-sub format {
- my ($self, $value, $type, $format) = @_;
- return "" if (!defined $value || $value eq "");
- if ($type eq "date") {
- if ($value =~ /^([0-9]{4})([0-9]{2})([0-9]{2})$/) {
- $value = "$1-$2-$3"; # time2str doesn't get YYYYMMDD
- }
- return "" if ($value eq "0000-00-00");
- return time2str($format, str2time($value));
- }
-}
-
-#############################################################################
-# Method: translate()
-#############################################################################
-
-=head2 translate()
-
- * Signature: $translated_label = $widget->translate($label, $lang);
- * Param: $label string
- * Param: $lang string
- * Return: $translated_label string
- * Throws: P5EEx::Blue::Exception
- * Since: 0.01
-
- $translated_label = $widget->translate($label, $lang);
- print $w->translate("Hello","fr"); # "Bonjour"
- print $w->translate("Hello","fr_ca"); # "Bonjour, eh" (french canadian)
-
-Translates the label into the desired language based on the dictionary
-which is current in the widget at the time.
-This dictionary is usually a reference to a global dictionary
-which is absorbed from the container widget.
-
-=cut
-
-sub translate {
- my ($self, $label, $lang) = @_;
-
- return $label if (!defined $label || $label eq ""); # can't translate a null
label
-
- my ($dict, $langlabel);
- $dict = $self->get("dict");
- return $label if (!defined $dict); # $dict is reqd for
translation
-
- if (defined $lang && $lang ne "") {
- $langlabel = $dict->{$lang}{$label};
- if (!defined $langlabel && $lang =~ s/_.*$//) { # trim the trailing
modifier (en_us => en)
- $langlabel = $dict->{$lang}{$label};
- }
- if (!defined $langlabel) {
- $langlabel = $dict->{default}{$label};
- }
- }
- return $label if (!defined $langlabel);
- return $langlabel;
-}
-
-#############################################################################
# Method: label()
#############################################################################
@@ -761,6 +622,149 @@
sub print {
my $self = shift;
print $self->dump();
+}
+
+#############################################################################
+# PUBLIC STATIC METHODS
+#############################################################################
+
+=head1 Public Static Methods:
+
+=cut
+
+#############################################################################
+# Method: format()
+#############################################################################
+
+=head2 format()
+
+ * Signature: $formatted_value = $self->format($value, $type, $format);
+ * Param: $value scalar
+ * Param: $type string
+ * Param: $format string
+ * Return: $formatted_value string
+ * Throws: P5EEx::Blue::Exception
+ * Since: 0.01
+
+ $formatted_value = $widget->format("20020127","date","%Y-%m-%d");
+ $formatted_value = $widget->format("27-Jan-02","date","%Y-%m-%d");
+ $formatted_value = $widget->format("01/27/2002","date","%Y-%m-%d");
+ $formatted_value = P5EEx::Blue::Widget->format("01/27/2002","date","%Y-%m-%d");
+
+A static method.
+
+=cut
+
+sub format {
+ my ($self, $value, $type, $format) = @_;
+ return "" if (!defined $value || $value eq "");
+ if ($type eq "date") {
+ if ($value =~ /^([0-9]{4})([0-9]{2})([0-9]{2})$/) {
+ $value = "$1-$2-$3"; # time2str doesn't get YYYYMMDD
+ }
+ return "" if ($value eq "0000-00-00");
+ return time2str($format, str2time($value));
+ }
+}
+
+#############################################################################
+# Method: translate()
+#############################################################################
+
+=head2 translate()
+
+ * Signature: $translated_label = $widget->translate($label, $lang);
+ * Param: $label string
+ * Param: $lang string
+ * Return: $translated_label string
+ * Throws: P5EEx::Blue::Exception
+ * Since: 0.01
+
+ $translated_label = $widget->translate($label, $lang);
+ print $w->translate("Hello","fr"); # "Bonjour"
+ print $w->translate("Hello","fr_ca"); # "Bonjour, eh" (french canadian)
+
+Translates the label into the desired language based on the dictionary
+which is current in the widget at the time.
+This dictionary is usually a reference to a global dictionary
+which is absorbed from the container widget.
+
+=cut
+
+sub translate {
+ my ($self, $label, $lang) = @_;
+
+ return $label if (!defined $label || $label eq ""); # can't translate a null
label
+
+ my ($dict, $langlabel);
+ $dict = $self->get("dict");
+ return $label if (!defined $dict); # $dict is reqd for
translation
+
+ if (defined $lang && $lang ne "") {
+ $langlabel = $dict->{$lang}{$label};
+ if (!defined $langlabel && $lang =~ s/_.*$//) { # trim the trailing
modifier (en_us => en)
+ $langlabel = $dict->{$lang}{$label};
+ }
+ if (!defined $langlabel) {
+ $langlabel = $dict->{default}{$label};
+ }
+ }
+ return $label if (!defined $langlabel);
+ return $langlabel;
+}
+
+#############################################################################
+# PROTECTED METHODS
+#############################################################################
+
+=head1 Protected Methods:
+
+=cut
+
+#############################################################################
+# Method: service_type()
+#############################################################################
+
+=head2 service_type()
+
+Returns 'Widget';
+
+ * Signature: $service_type = P5EEx::Blue::Widget->service_type();
+ * Param: void
+ * Return: $service_type string
+ * Since: 0.01
+
+ $service_type = $widget->service_type();
+
+=cut
+
+sub service_type () { 'Widget'; }
+
+#############################################################################
+# Method: absorbable_attribs()
+#############################################################################
+
+=head2 absorbable_attribs()
+
+Returns a list of attributes which a service of this type would like to
+absorb from its container service.
+This is a *static* method.
+It doesn't require an instance of the class to call it.
+
+ * Signature: $attribs = P5EEx::Blue::Service->absorbable_attribs()
+ * Param: void
+ * Return: $attribs []
+ * Throws: P5EEx::Blue::Exception
+ * Since: 0.01
+
+ $attribs = $widget->absorbable_attribs();
+ @attribs = @{$widget->absorbable_attribs()};
+
+=cut
+
+sub absorbable_attribs {
+ # for the general widget, there are only a few universal absorbable attributes
+ [ "lang", "dict" ];
}
=head1 ACKNOWLEDGEMENTS