Author: vetinari
Date: Fri Jun 27 01:44:33 2008
New Revision: 930
Modified:
contrib/vetinari/ContentType.pm
Log:
ContentType.pm: - add format(), update pod
Modified: contrib/vetinari/ContentType.pm
==============================================================================
--- contrib/vetinari/ContentType.pm (original)
+++ contrib/vetinari/ContentType.pm Fri Jun 27 01:44:33 2008
@@ -50,10 +50,19 @@
The subtype if the MIME-Type, e.g. B<plain> for a I<text/plain> type.
-=head2 param(NAME)
+=head2 param(NAME [,VALUE])
Returns the value of the parameter NAME or I<undef()> if not present in
the Content-Type header.
+If a VALUE is given, it sets the parameter NAME to VALUE, useful with
+C<format()>.
+
+=head2 format( )
+
+Returns a string, which may be used to replace the current C<Content-Type>
+header
+
+ $transaction->header->replace("Content-Type", $ct->format);
=cut
@@ -238,5 +247,14 @@
}
return ($self->{$key} || undef);
}
+sub format {
+ my $self = shift;
+ my $str = $self->type.'/'.$self->subtype;
+ foreach (keys %{$self}) {
+ next if /^ /;
+ $str .= "; $_=\"".$self->param($_)."\"";
+ }
+ return $str;
+}
1;