2 package Module::Install::RTx;
9 use Module::Install::Base;
10 use base 'Module::Install::Base';
11 our $VERSION = '0.22';
15 use File::Basename ();
18 my ( $self, $name ) = @_;
20 my $original_name = $name;
22 $RTx = $1 if $name =~ s/^(\w+)-//;
26 $self->name("$RTx-$name")
28 $self->all_from( -e "$name.pm" ? "$name.pm" : "lib/$RTx/$fname.pm" )
29 unless $self->version;
30 $self->abstract("RT $name Extension")
31 unless $self->abstract;
33 my @prefixes = (qw(/opt /usr/local /home /usr /sw ));
34 my $prefix = $ENV{PREFIX};
35 @ARGV = grep { /PREFIX=(.*)/ ? ( ( $prefix = $1 ), 0 ) : 1 } @ARGV;
38 $RT::LocalPath = $prefix;
39 $INC{'RT.pm'} = "$RT::LocalPath/lib/RT.pm";
43 $ENV{RTHOME} ? ( $ENV{RTHOME}, "$ENV{RTHOME}/lib" ) : (),
44 map { ( "$_/rt3/lib", "$_/lib/rt3", "$_/lib" ) } grep $_,
47 until ( eval { require RT; $RT::LocalPath } ) {
49 "Cannot find the location of RT.pm that defines \$RT::LocalPath in: @INC\n";
50 $_ = $self->prompt("Path to your RT.pm:") or exit;
51 push @INC, $_, "$_/rt3/lib", "$_/lib/rt3", "$_/lib";
55 my $lib_path = File::Basename::dirname( $INC{'RT.pm'} );
56 my $local_lib_path = "$RT::LocalPath/lib";
57 print "Using RT configuration from $INC{'RT.pm'}:\n";
58 unshift @INC, "$RT::LocalPath/lib" if $RT::LocalPath;
60 $RT::LocalVarPath ||= $RT::VarPath;
61 $RT::LocalPoPath ||= $RT::LocalLexiconPath;
62 $RT::LocalHtmlPath ||= $RT::MasonComponentRoot;
65 my $with_subdirs = $ENV{WITH_SUBDIRS};
66 @ARGV = grep { /WITH_SUBDIRS=(.*)/ ? ( ( $with_subdirs = $1 ), 0 ) : 1 }
70 %subdirs = map { $_ => 1 } split( /\s*,\s*/, $with_subdirs )
71 if defined $with_subdirs;
73 foreach (qw(bin etc html po sbin var)) {
74 next unless -d "$FindBin::Bin/$_";
75 next if keys %subdirs and !$subdirs{$_};
76 $self->no_index( directory => $_ );
79 my $varname = "RT::Local" . ucfirst($_) . "Path";
80 $path{$_} = ${$varname} || "$RT::LocalPath/$_";
83 $path{$_} .= "/$name" for grep $path{$_}, qw(etc po var);
84 $path{lib} = "$RT::LocalPath/lib" unless keys %subdirs and !$subdirs{'lib'};
86 # If we're running on RT 3.8 with plugin support, we really wany
87 # to install libs, mason templates and po files into plugin specific
89 if ($RT::LocalPluginPath) {
90 foreach my $path (qw(lib po html etc bin sbin)) {
91 next unless -d "$FindBin::Bin/$path";
92 next if %subdirs and !$subdirs{$path};
93 $path{$path} = $RT::LocalPluginPath . "/$original_name/$path";
97 my $args = join( ', ', map "q($_)", %path );
98 print "./$_\t=> $path{$_}\n" for sort keys %path;
100 if ( my @dirs = map { ( -D => $_ ) } grep $path{$_}, qw(bin html sbin) ) {
101 my @po = map { ( -o => $_ ) } grep -f,
102 File::Glob::bsd_glob("po/*.po");
103 $self->postamble(<< ".") if @po;
105 \t\$(NOECHO) \$(PERL) -MLocale::Maketext::Extract::Run=xgettext -e \"xgettext(qw(@dirs @po))\"
109 my $postamble = << ".";
111 \t\$(NOECHO) \$(PERL) -MExtUtils::Install -e \"install({$args})\"
114 if ( $path{var} and -d $RT::MasonDataDir ) {
115 my ( $uid, $gid ) = ( stat($RT::MasonDataDir) )[ 4, 5 ];
116 $postamble .= << ".";
117 \t\$(NOECHO) chown -R $uid:$gid $path{var}
122 if ( File::Glob::bsd_glob("$FindBin::Bin/etc/schema.*") ) {
124 # got schema, load factory module
126 $self->load('RTxFactory');
127 $self->postamble(<< ".");
129 \t\$(NOECHO) \$(PERL) -Ilib -I"$local_lib_path" -I"$lib_path" -Minc::Module::Install -e"RTxFactory(qw($RTx $name))"
132 \t\$(NOECHO) \$(PERL) -Ilib -I"$local_lib_path" -I"$lib_path" -Minc::Module::Install -e"RTxFactory(qw($RTx $name drop))"
136 if ( File::Glob::bsd_glob("$FindBin::Bin/etc/acl.*") ) {
139 if ( -e 'etc/initialdata' ) { $has_etc{initialdata}++; }
141 $self->postamble("$postamble\n");
142 if ( %subdirs and !$subdirs{'lib'} ) {
143 $self->makemaker_args( PM => { "" => "" }, );
145 $self->makemaker_args( INSTALLSITELIB => "$RT::LocalPath/lib" );
148 $self->makemaker_args( INSTALLSITEMAN1DIR => "$RT::LocalPath/man/man1" );
149 $self->makemaker_args( INSTALLSITEMAN3DIR => "$RT::LocalPath/man/man3" );
150 $self->makemaker_args( INSTALLSITEARCH => "$RT::LocalPath/man" );
151 $self->makemaker_args( INSTALLARCHLIB => "$RT::LocalPath/lib" );
153 $self->load('RTxInitDB');
154 print "For first-time installation, type 'make initdb'.\n";
156 $initdb .= <<"." if $has_etc{schema};
157 \t\$(NOECHO) \$(PERL) -Ilib -I"$local_lib_path" -I"$lib_path" -Minc::Module::Install -e"RTxInitDB(qw(schema))"
159 $initdb .= <<"." if $has_etc{acl};
160 \t\$(NOECHO) \$(PERL) -Ilib -I"$local_lib_path" -I"$lib_path" -Minc::Module::Install -e"RTxInitDB(qw(acl))"
162 $initdb .= <<"." if $has_etc{initialdata};
163 \t\$(NOECHO) \$(PERL) -Ilib -I"$local_lib_path" -I"$lib_path" -Minc::Module::Install -e"RTxInitDB(qw(insert))"
165 $self->postamble("initdb ::\n$initdb\n");
166 $self->postamble("initialize-database ::\n$initdb\n");
171 unshift @INC, substr( delete( $INC{'RT.pm'} ), 0, -5 ) if $INC{'RT.pm'};
174 RT::ConnectToDatabase();
176 die "Cannot load RT" unless $RT::Handle and $RT::DatabaseType;