[Rt-commit] r10525 - in rt/branches/3.999-DANGEROUS: lib/RT
jesse at bestpractical.com
jesse at bestpractical.com
Mon Jan 28 15:31:42 EST 2008
Author: jesse
Date: Mon Jan 28 15:31:33 2008
New Revision: 10525
Modified:
rt/branches/3.999-DANGEROUS/ (props changed)
rt/branches/3.999-DANGEROUS/lib/RT/Config.pm
Log:
r75799 at pinglin: jesse | 2008-01-28 15:30:51 -0500
* small cleanup to Config.pm
Modified: rt/branches/3.999-DANGEROUS/lib/RT/Config.pm
==============================================================================
--- rt/branches/3.999-DANGEROUS/lib/RT/Config.pm (original)
+++ rt/branches/3.999-DANGEROUS/lib/RT/Config.pm Mon Jan 28 15:31:33 2008
@@ -1,40 +1,40 @@
# BEGIN BPS TAGGED BLOCK {{{
-#
+#
# COPYRIGHT:
-#
-# This software is Copyright (c) 1996-2007 Best Practical Solutions, LLC
+#
+# This software is Copyright (c) 1996-2007 Best Practical Solutions, LLC
# <jesse at bestpractical.com>
-#
+#
# (Except where explicitly superseded by other copyright notices)
-#
-#
+#
+#
# LICENSE:
-#
+#
# This work is made available to you under the terms of Version 2 of
# the GNU General Public License. A copy of that license should have
# been provided with this software, but in any event can be snarfed
# from www.gnu.org.
-#
+#
# This work is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
-#
+#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
# 02110-1301 or visit their web page on the internet at
# http://www.gnu.org/copyleft/gpl.html.
-#
-#
+#
+#
# CONTRIBUTION SUBMISSION POLICY:
-#
+#
# (The following paragraph is not intended to limit the rights granted
# to you to modify and distribute this software under the terms of
# the GNU General Public License and is only of importance to you if
# you choose to contribute your changes and enhancements to the
# community by submitting them to Best Practical Solutions, LLC.)
-#
+#
# By intentionally submitting any modifications, corrections or
# derivatives to this work, or any other work intended for use with
# Request Tracker, to Best Practical Solutions, LLC, you confirm that
@@ -43,7 +43,7 @@
# royalty-free, perpetual, license to use, copy, create derivative
# works based on those contributions, and sublicense and distribute
# those contributions and any derivatives thereof.
-#
+#
# END BPS TAGGED BLOCK }}}
use strict;
@@ -98,13 +98,13 @@
our %META = (
WebDefaultStylesheet => {
- Section => 'General', #loc
+ Section => 'General', #loc
Overridable => 1,
Widget => '/Widgets/Form/Select',
WidgetArguments => {
- Description => 'Interface style', #loc
- # XXX: we need support for 'get values callback'
- Values => [qw(3.5-default 3.4-compat)],
+ Description => 'Interface style', #loc
+ # XXX: we need support for 'get values callback'
+ Values => [qw(3.5-default 3.4-compat)],
},
},
DefaultSummaryRows => {
@@ -112,7 +112,9 @@
Overridable => 1,
Widget => '/Widgets/Form/Integer',
WidgetArguments => {
- Description => 'Number of rows displayed in search results on the frontpage', #loc
+ Description =>
+ 'Number of rows displayed in search results on the frontpage'
+ , #loc
},
},
MessageBoxWidth => {
@@ -120,7 +122,7 @@
Overridable => 1,
Widget => '/Widgets/Form/Integer',
WidgetArguments => {
- Description => 'Message box width', #loc
+ Description => 'Message box width', #loc
},
},
MessageBoxHeight => {
@@ -128,15 +130,17 @@
Overridable => 1,
Widget => '/Widgets/Form/Integer',
WidgetArguments => {
- Description => 'Message box height', #loc
+ Description => 'Message box height', #loc
},
},
MaxInlineBody => {
- Section => 'Ticket display', #loc
+ Section => 'Ticket display', #loc
Overridable => 1,
Widget => '/Widgets/Form/Integer',
WidgetArguments => {
- Description => 'Maximum size of messages (in bytes) that should be inlined in ticket history; A value of 0 (zero) will always inline', #loc
+ Description =>
+ 'Maximum size of messages (in bytes) that should be inlined in ticket history; A value of 0 (zero) will always inline'
+ , #loc
},
},
OldestTransactionsFirst => {
@@ -144,33 +148,27 @@
Overridable => 1,
Widget => '/Widgets/Form/Boolean',
WidgetArguments => {
- Description => 'Show oldest transactions first', #loc
+ Description => 'Show oldest transactions first', #loc
},
},
- DateTimeFormat => {
- Section => 'Date and time', #loc
+ DateTimeFormat => {
+ Section => 'Date and time', #loc
Overridable => 1,
Widget => '/Widgets/Form/Select',
WidgetArguments => {
- Description => 'Date and time output format', #loc
- Values => [qw(DefaultFormat RFC2822 ISO W3CDTF)],
+ Description => 'Date and time output format', #loc
+ Values => [qw(DefaultFormat RFC2822 ISO W3CDTF)],
values_label => {
- DefaultFormat => 'Default (Tue Dec 25 21:59:12 1995)', #loc
+ DefaultFormat => 'Default (Tue Dec 25 21:59:12 1995)', #loc
RFC2822 => 'RFC (Tue, 25 Dec 1995 21:59:12 -0300)', #loc
- ISO => 'ISO (1995-11-25 21:59:12)', #loc
- W3CDTF => 'W3C (1995-11-25T21:59:12Z)', #loc
+ ISO => 'ISO (1995-11-25 21:59:12)', #loc
+ W3CDTF => 'W3C (1995-11-25T21:59:12Z)', #loc
},
},
},
- MailPlugins => {
- Type => 'ARRAY'
- },
- GnuPG => {
- Type => 'HASH'
- },
- GnuPGOptions => {
- Type => 'HASH'
- },
+ MailPlugins => { Type => 'ARRAY' },
+ GnuPG => { Type => 'HASH' },
+ GnuPGOptions => { Type => 'HASH' },
);
my %OPTIONS = ();
@@ -184,8 +182,8 @@
sub new {
my $proto = shift;
- my $class = ref($proto)? ref($proto): $proto;
- my $self = bless {}, $class;
+ my $class = ref($proto) ? ref($proto) : $proto;
+ my $self = bless {}, $class;
$self->_init(@_);
return $self;
}
@@ -196,10 +194,9 @@
=cut
-sub InitConfig
-{
+sub init_config {
my $self = shift;
- my %args = (File => '', @_);
+ my %args = ( File => '', @_ );
$args{'File'} =~ s/(?<=Config)(?=\.pm$)/Meta/;
return 1;
}
@@ -212,9 +209,8 @@
=cut
-sub load_configs
-{
- my $self = shift;
+sub load_configs {
+ my $self = shift;
my @configs = $self->configs;
$self->init_config( File => $_ ) foreach @configs;
$self->load_config( File => $_ ) foreach @configs;
@@ -236,35 +232,34 @@
=cut
-sub load_config
-{
+sub load_config {
my $self = shift;
- my %args = (File => '', @_);
+ my %args = ( File => '', @_ );
$args{'File'} =~ s/(?<!Site)(?=Config\.pm$)/Site/;
- if ($args{'File'} eq 'RT_SiteConfig.pm' and my $site_config = $ENV{RT_SITE_CONFIG}) {
+ if ( $args{'File'} eq 'RT_SiteConfig.pm'
+ and my $site_config = $ENV{RT_SITE_CONFIG} )
+ {
$self->_load_config( %args, File => $site_config );
- }
- else {
- $self->_load_config( %args );
+ } else {
+ $self->_load_config(%args);
}
$args{'File'} =~ s/Site(?=Config\.pm$)//;
- $self->_load_config( %args );
+ $self->_load_config(%args);
return 1;
}
-sub _load_config
-{
+sub _load_config {
my $self = shift;
- my %args = (File => '', @_);
+ my %args = ( File => '', @_ );
- my $is_ext = $args{'File'} !~ /^RT_(?:Site)?Config/? 1: 0;
- my $is_site = $args{'File'} =~ /SiteConfig/? 1: 0;
+ my $is_ext = $args{'File'} !~ /^RT_(?:Site)?Config/ ? 1 : 0;
+ my $is_site = $args{'File'} =~ /SiteConfig/ ? 1 : 0;
eval {
package RT;
local *set = sub(\[$@%]@) {
- my ($opt_ref, @args) = @_;
- my ($pack, $file, $line) = caller;
+ my ( $opt_ref, @args ) = @_;
+ my ( $pack, $file, $line ) = caller;
return $self->set_from_config(
Option => $opt_ref,
Value => [@args],
@@ -275,30 +270,31 @@
Extension => $is_ext,
);
};
- local @INC = ($RT::LocalEtcPath, $RT::EtcPath, @INC);
+ local @INC = ( $RT::LocalEtcPath, $RT::EtcPath, @INC );
require $args{'File'};
};
- if( $@ ) {
+ if ($@) {
return 1 if $is_site && $@ =~ qr{^Can't locate \Q$args{File}};
if ( $is_site || $@ !~ qr{^Can't locate \Q$args{File}} ) {
die qq{Couldn't load RT config file $args{'File'}:\n\n$@};
}
my $username = getpwuid($>);
- my $group = getgrgid($();
+ my $group = getgrgid($();
- my ($file_path, $fileuid, $filegid);
+ my ( $file_path, $fileuid, $filegid );
foreach ( $RT::LocalEtcPath, $RT::EtcPath, @INC ) {
my $tmp = File::Spec->catfile( $_, $args{File} );
- ($fileuid,$filegid) = (stat( $tmp ))[4,5];
+ ( $fileuid, $filegid ) = ( stat($tmp) )[ 4, 5 ];
if ( defined $fileuid ) {
$file_path = $tmp;
last;
}
}
- unless ( $file_path ) {
- die qq{Couldn't load RT config file $args{'File'} as user $username / group $group.\n}
- .qq{The file couldn't be find in $RT::LocalEtcPath and $RT::EtcPath.\n$@};
+ unless ($file_path) {
+ die
+ qq{Couldn't load RT config file $args{'File'} as user $username / group $group.\n}
+ . qq{The file couldn't be find in $RT::LocalEtcPath and $RT::EtcPath.\n$@};
}
my $message = <<EOF;
@@ -317,10 +313,9 @@
EOF
my $fileusername = getpwuid($fileuid);
- my $filegroup = getgrgid($filegid);
- my $errormessage = sprintf($message,
- $file_path, $fileusername, $filegroup, $filegroup
- );
+ my $filegroup = getgrgid($filegid);
+ my $errormessage = sprintf( $message,
+ $file_path, $fileusername, $filegroup, $filegroup );
die "$errormessage\n$@";
}
return 1;
@@ -333,26 +328,24 @@
=cut
-sub Configs
-{
- my $self = shift;
+sub configs {
+ my $self = shift;
my @configs = ();
- foreach my $path( $RT::LocalEtcPath, $RT::EtcPath ) {
- my $mask = File::Spec->catfile($path, "*_Config.pm");
+ foreach my $path ( $RT::LocalEtcPath, $RT::EtcPath ) {
+ my $mask = File::Spec->catfile( $path, "*_Config.pm" );
my @files = glob $mask;
- @files = grep !/^RT_Config\.pm$/,
- grep $_ && /^\w+_Config\.pm$/,
- map { s/^.*[\\\/]//; $_ } @files;
+ @files = grep !/^RT_Config\.pm$/, grep $_ && /^\w+_Config\.pm$/,
+ map { s/^.*[\\\/]//; $_ } @files;
push @configs, @files;
}
@configs = sort @configs;
- unshift(@configs, 'RT_Config.pm');
+ unshift( @configs, 'RT_Config.pm' );
return @configs;
}
-=head2 Get
+=head2 get
Takes name of the option as argument and returns its current value.
@@ -376,16 +369,16 @@
=cut
sub get {
- my ($self, $name, $user) = @_;
+ my ( $self, $name, $user ) = @_;
my $res;
- if ( $user && $META{ $name }->{'Overridable'} ) {
+ if ( $user && $META{$name}->{'Overridable'} ) {
$user = $user->user_object if $user->isa('RT::CurrentUser');
my $prefs = $user->preferences( RT->system );
- $res = $prefs->{ $name } if $prefs;
+ $res = $prefs->{$name} if $prefs;
}
- $res = $OPTIONS{ $name } unless defined $res;
- return $self->_return_value($res, $META{ $name }->{'Type'} || 'SCALAR');
+ $res = $OPTIONS{$name} unless defined $res;
+ return $self->_return_value( $res, $META{$name}->{'Type'} || 'SCALAR' );
}
=head2 Set
@@ -400,128 +393,131 @@
=cut
sub set {
- my ($self, $name) = (shift, shift);
-
- my $old = $OPTIONS{ $name };
- my $type = $META{ $name }->{'Type'} || 'SCALAR';
+ my ( $self, $name ) = ( shift, shift );
+
+ my $old = $OPTIONS{$name};
+ my $type = $META{$name}->{'Type'} || 'SCALAR';
if ( $type eq 'ARRAY' ) {
- $OPTIONS{$name} = [ @_ ];
- { no strict 'refs'; @{"RT::$name"} = (@_); }
+ $OPTIONS{$name} = [@_];
+ { no strict 'refs'; @{"RT::$name"} = (@_); }
} elsif ( $type eq 'HASH' ) {
- $OPTIONS{$name} = { @_ };
- { no strict 'refs'; %{"RT::$name"} = (@_); }
+ $OPTIONS{$name} = {@_};
+ { no strict 'refs'; %{"RT::$name"} = (@_); }
} else {
$OPTIONS{$name} = shift;
- { no strict 'refs'; ${"RT::$name"} = $OPTIONS{$name}; }
+ { no strict 'refs'; ${"RT::$name"} = $OPTIONS{$name}; }
}
$META{$name}->{'Type'} = $type;
- return $self->_return_value($old, $type);
+ return $self->_return_value( $old, $type );
}
sub _return_value {
- my ($self, $res, $type) = @_;
+ my ( $self, $res, $type ) = @_;
return $res unless wantarray;
- if( $type eq 'ARRAY' ) {
+ if ( $type eq 'ARRAY' ) {
return @{ $res || [] };
- } elsif( $type eq 'HASH' ) {
+ } elsif ( $type eq 'HASH' ) {
return %{ $res || {} };
}
return $res;
}
-sub set_from_config
-{
+sub set_from_config {
my $self = shift;
my %args = (
- Option => undef,
- value => [],
- Package => 'RT',
- File => '',
- Line => 0,
+ Option => undef,
+ value => [],
+ Package => 'RT',
+ File => '',
+ Line => 0,
SiteConfig => 1,
- Extension => 0,
+ Extension => 0,
@_
);
unless ( $args{'File'} ) {
- ($args{'Package'}, $args{'File'}, $args{'Line'}) = caller(1);
+ ( $args{'Package'}, $args{'File'}, $args{'Line'} ) = caller(1);
}
my $opt = $args{'Option'};
my $type;
- my $name = $self->__getname_by_ref( $opt );
- if( $name ) {
+ my $name = $self->__getname_by_ref($opt);
+ if ($name) {
$type = ref $opt;
$name =~ s/.*:://;
} else {
$name = $$opt;
- $type = $META{ $name }->{'Type'} || 'SCALAR';
+ $type = $META{$name}->{'Type'} || 'SCALAR';
}
- return 1 if exists $OPTIONS{ $name } && !$args{'SiteConfig'};
+ return 1 if exists $OPTIONS{$name} && !$args{'SiteConfig'};
- $META{ $name }->{'Type'} = $type;
- foreach ( qw(Package File Line SiteConfig Extension) ) {
- $META{ $name }->{'Source'}->{$_} = $args{$_};
+ $META{$name}->{'Type'} = $type;
+ foreach (qw(Package File Line SiteConfig Extension)) {
+ $META{$name}->{'Source'}->{$_} = $args{$_};
}
$self->set( $name, @{ $args{'Value'} } );
return 1;
}
-{ my $last_pack = '';
-sub __GetnameByRef
{
- my $self = shift;
- my $ref = shift;
- my $pack = shift;
- if ( !$pack && $last_pack ) {
- my $tmp = $self->__getname_by_ref( $ref, $last_pack );
- return $tmp if $tmp;
- }
- $pack ||= 'main::';
- $pack .= '::' unless substr($pack, -2) eq '::';
-
- my %ref_sym = (
- SCALAR => '$',
- ARRAY => '@',
- HASH => '%',
- CODE => '&',
- );
- no strict 'refs';
- my $name = undef;
- # scan $pack name table(hash)
- foreach my $k( keys %{$pack} ) {
- # hash for main:: has reference on itself
- next if $k eq 'main::';
-
- # if entry has trailing '::' then
- # it is link to other name space
- if ( $k =~ /::$/ ) {
- $name = $self->__getname_by_ref($ref, $k);
- return $name if $name;
+ my $last_pack = '';
+
+ sub __getname_by_ref {
+ my $self = shift;
+ my $ref = shift;
+ my $pack = shift;
+ if ( !$pack && $last_pack ) {
+ my $tmp = $self->__getname_by_ref( $ref, $last_pack );
+ return $tmp if $tmp;
}
+ $pack ||= 'main::';
+ $pack .= '::' unless substr( $pack, -2 ) eq '::';
+
+ my %ref_sym = (
+ SCALAR => '$',
+ ARRAY => '@',
+ HASH => '%',
+ CODE => '&',
+ );
+ no strict 'refs';
+ my $name = undef;
+
+ # scan $pack name table(hash)
+ foreach my $k ( keys %{$pack} ) {
- # entry of the table with references to
- # SCALAR, ARRAY... and other types with
- # the same name
- my $entry = ${$pack}{$k};
- next unless $entry;
-
- # get entry for type we are looking for
- my $entry_ref = *{$entry}{ref($ref)};
- next unless $entry_ref;
-
- # if references are equal then we've found
- if( $entry_ref == $ref ) {
- $last_pack = $pack;
- return ($ref_sym{ref($ref)} || '*') . $pack . $k;
+ # hash for main:: has reference on itself
+ next if $k eq 'main::';
+
+ # if entry has trailing '::' then
+ # it is link to other name space
+ if ( $k =~ /::$/ ) {
+ $name = $self->__getname_by_ref( $ref, $k );
+ return $name if $name;
+ }
+
+ # entry of the table with references to
+ # SCALAR, ARRAY... and other types with
+ # the same name
+ my $entry = ${$pack}{$k};
+ next unless $entry;
+
+ # get entry for type we are looking for
+ my $entry_ref = *{$entry}{ ref($ref) };
+ next unless $entry_ref;
+
+ # if references are equal then we've found
+ if ( $entry_ref == $ref ) {
+ $last_pack = $pack;
+ return ( $ref_sym{ ref($ref) } || '*' ) . $pack . $k;
+ }
}
+ return '';
}
- return '';
-} }
+}
=head2 Metadata
@@ -531,25 +527,28 @@
=cut
sub meta {
- return $META{$_[1]};
+ return $META{ $_[1] };
}
sub sections {
my $self = shift;
my %seen;
return sort
- grep !$seen{$_}++,
- map $_->{'Section'} || 'General',
- values %META;
+ grep !$seen{$_}++, map $_->{'Section'} || 'General', values %META;
}
sub options {
my $self = shift;
my %args = ( Section => undef, Overridable => 1, @_ );
- my @res = sort keys %META;
- @res = grep( ( $META{$_}->{'Section'} || 'General' ) eq $args{'Section'}, @res ) if defined $args{'Section'};
+ my @res = sort keys %META;
+ @res = grep( ( $META{$_}->{'Section'} || 'General' ) eq $args{'Section'},
+ @res )
+ if defined $args{'Section'};
if ( defined $args{'Overridable'} ) {
- @res = grep( ( $META{$_}->{'Overridable'} || 0 ) == $args{'Overridable'}, @res );
+ @res
+ = grep(
+ ( $META{$_}->{'Overridable'} || 0 ) == $args{'Overridable'},
+ @res );
}
return @res;
}
More information about the Rt-commit
mailing list