[Bps-public-commit] rt-extension-customizecontenttype branch, master, updated. 57765268a0927e3b3c31c5d72208112172bb799d
? sunnavy
sunnavy at bestpractical.com
Tue Apr 10 11:40:36 EDT 2012
The branch, master has been updated
via 57765268a0927e3b3c31c5d72208112172bb799d (commit)
from 97f446f517887f6562dcb4e2a92fa012dfbaed3b (commit)
Summary of changes:
lib/RT/Extension/CustomizeContentType.pm | 29 +++++++++++++++++++++++------
1 files changed, 23 insertions(+), 6 deletions(-)
- Log -----------------------------------------------------------------
commit 57765268a0927e3b3c31c5d72208112172bb799d
Author: sunnavy <sunnavy at bestpractical.com>
Date: Tue Apr 10 23:40:28 2012 +0800
in case method RT::Attachment::ContentType is defined already(not the AUTOLOAD one)
diff --git a/lib/RT/Extension/CustomizeContentType.pm b/lib/RT/Extension/CustomizeContentType.pm
index d193721..2f503f4 100644
--- a/lib/RT/Extension/CustomizeContentType.pm
+++ b/lib/RT/Extension/CustomizeContentType.pm
@@ -8,18 +8,35 @@ use RT::Attachment;
package RT::Attachment;
-sub ContentType {
- my $self = shift;
-
- my $content_type = $self->_Value('ContentType');
- return $content_type unless $content_type;
+my $new = sub {
+ my $self = shift;
+ my $content_type = shift;
return $content_type
unless $self->Filename && $self->Filename =~ /\.(\w+)$/;
- my $ext = $1;
+ my $ext = $1;
my $config = RT->Config->Get('ContentTypes') or return $content_type;
return $config->{$ext} || $content_type;
+};
+
+my $old = __PACKAGE__->can('ContentType');
+if ($old) {
+ no warnings 'redefine';
+ *ContentType = sub {
+ my $self = shift;
+ my $content_type = $old->( $self, @_ );
+ return $content_type unless defined $content_type;
+ return $new->( $self, $content_type );
+ };
+}
+else {
+ *ContentType = sub {
+ my $self = shift;
+ my $content_type = $self->_Value('ContentType');
+ return $content_type unless defined $content_type;
+ return $new->( $self, $content_type );
+ };
}
1;
-----------------------------------------------------------------------
More information about the Bps-public-commit
mailing list