[Rt-commit] r5866 - in RT-Extension-TicketAging: . etc inc inc/Module inc/Module/Install inc/Module/Install/RTx lib lib/RT lib/RT/Extension t

ruz at bestpractical.com ruz at bestpractical.com
Tue Sep 5 17:27:45 EDT 2006


Author: ruz
Date: Tue Sep  5 17:27:43 2006
New Revision: 5866

Added:
   RT-Extension-TicketAging/MANIFEST
   RT-Extension-TicketAging/META.yml
   RT-Extension-TicketAging/Makefile.PL
   RT-Extension-TicketAging/SPECIFICATION
   RT-Extension-TicketAging/etc/
   RT-Extension-TicketAging/etc/initialdata
   RT-Extension-TicketAging/inc/
   RT-Extension-TicketAging/inc/Module/
   RT-Extension-TicketAging/inc/Module/AutoInstall.pm
   RT-Extension-TicketAging/inc/Module/Install/
   RT-Extension-TicketAging/inc/Module/Install.pm
   RT-Extension-TicketAging/inc/Module/Install/AutoInstall.pm
   RT-Extension-TicketAging/inc/Module/Install/Base.pm
   RT-Extension-TicketAging/inc/Module/Install/Can.pm
   RT-Extension-TicketAging/inc/Module/Install/Fetch.pm
   RT-Extension-TicketAging/inc/Module/Install/Include.pm
   RT-Extension-TicketAging/inc/Module/Install/Makefile.pm
   RT-Extension-TicketAging/inc/Module/Install/Metadata.pm
   RT-Extension-TicketAging/inc/Module/Install/RTx/
   RT-Extension-TicketAging/inc/Module/Install/RTx.pm
   RT-Extension-TicketAging/inc/Module/Install/RTx/Factory.pm
   RT-Extension-TicketAging/inc/Module/Install/Substitute.pm
   RT-Extension-TicketAging/inc/Module/Install/Win32.pm
   RT-Extension-TicketAging/inc/Module/Install/WriteAll.pm
   RT-Extension-TicketAging/lib/
   RT-Extension-TicketAging/lib/RT/
   RT-Extension-TicketAging/lib/RT/Extension/
   RT-Extension-TicketAging/lib/RT/Extension/TicketAging.pm
   RT-Extension-TicketAging/sbin/
   RT-Extension-TicketAging/sbin/rt-aging   (contents, props changed)
   RT-Extension-TicketAging/t/
   RT-Extension-TicketAging/t/00.load.t
   RT-Extension-TicketAging/t/01.basics.t
   RT-Extension-TicketAging/t/02.finished-age.t
   RT-Extension-TicketAging/t/03.dead-age.t
   RT-Extension-TicketAging/t/04.extinct-age.t
   RT-Extension-TicketAging/t/05.destroyed-age.t
   RT-Extension-TicketAging/t/utils.pl

Log:
* initial checkin

Added: RT-Extension-TicketAging/MANIFEST
==============================================================================
--- (empty file)
+++ RT-Extension-TicketAging/MANIFEST	Tue Sep  5 17:27:43 2006
@@ -0,0 +1,28 @@
+etc/initialdata
+inc/Module/AutoInstall.pm
+inc/Module/Install.pm
+inc/Module/Install/AutoInstall.pm
+inc/Module/Install/Base.pm
+inc/Module/Install/Can.pm
+inc/Module/Install/Fetch.pm
+inc/Module/Install/Include.pm
+inc/Module/Install/Makefile.pm
+inc/Module/Install/Metadata.pm
+inc/Module/Install/RTx.pm
+inc/Module/Install/RTx/Factory.pm
+inc/Module/Install/Substitute.pm
+inc/Module/Install/Win32.pm
+inc/Module/Install/WriteAll.pm
+lib/RT/Extension/TicketAging.pm
+Makefile.PL
+MANIFEST			This list of files
+META.yml
+sbin/rt-aging
+SPECIFICATION
+t/00.load.t
+t/01.basics.t
+t/02.finished-age.t
+t/03.dead-age.t
+t/04.extinct-age.t
+t/05.destroyed-age.t
+t/utils.pl

Added: RT-Extension-TicketAging/META.yml
==============================================================================
--- (empty file)
+++ RT-Extension-TicketAging/META.yml	Tue Sep  5 17:27:43 2006
@@ -0,0 +1,15 @@
+abstract: RT Extension-TicketAging Extension
+author: Ruslan Zakirov <ruz at bestpractical.com>
+build_requires: 
+  Test::More: 0
+distribution_type: module
+generated_by: Module::Install version 0.64
+license: perl
+name: RT-Extension-TicketAging
+no_index: 
+  directory: 
+    - etc
+    - sbin
+    - inc
+    - t
+version: 0.04

Added: RT-Extension-TicketAging/Makefile.PL
==============================================================================
--- (empty file)
+++ RT-Extension-TicketAging/Makefile.PL	Tue Sep  5 17:27:43 2006
@@ -0,0 +1,25 @@
+use inc::Module::Install;
+
+#die "This RT Extension will kill your pets and steal your valuables. DO NOT USE IT YET";
+RTx ('RT-Extension-TicketAging');
+author ('Ruslan Zakirov <ruz at bestpractical.com>');
+license('perl');
+
+build_requires('Test::More');
+auto_install();
+
+my ($lp) = ($INC{'RT.pm'} =~ /^(.*)[\\\/]/);
+my $lib_path = join( ' ', "$RT::LocalPath/lib", $lp );
+my $sbin_path = $RT::SbinPath || "$RT::BasePath/sbin" || "/opt/rt3/sbin";
+my $bin_path = $RT::BinPath || "$RT::BasePath/bin" || "/opt/rt3/bin";
+
+substitute(
+    {
+        RT_LIB_PATH  => $lib_path,
+        RT_BIN_PATH  => $bin_path,
+        RT_SBIN_PATH => $sbin_path,
+    },
+    qw(t/utils.pl),
+);
+
+WriteAll();

Added: RT-Extension-TicketAging/SPECIFICATION
==============================================================================
--- (empty file)
+++ RT-Extension-TicketAging/SPECIFICATION	Tue Sep  5 17:27:43 2006
@@ -0,0 +1,182 @@
+
+
+= Specification of RT-Extension-TicketAging
+
+Version: 0.4
+Author: Ruslan U. Zakirov <ruz at bestpractical.com>
+
+== INTRODUCTION
+
+RTIR MUST support a scheme for incident aging in which closed
+incidents and associated tickets are made inaccessible through
+the normal interface and are eventually removed from the database.
+
+*Note* that this removal is in most cases necessary to comply with
+EU and other legislation.
+
+One possible life cycle model is:
+• Active
+• Finished (no further activity expected, 2 month timeout)
+• Dead (remains available for searching, 12 month timeout)
+• Extinct (out of band access only, 6 month timeout)
+• Destroyed (out of band procedure for destroying backups)
+
+== IMPLEMENTATION
+
+As RTIR is extension over RT core and aging make sense for
+none RTIR tickets too, so it was decided to make extension
+for RT that also would be compatible with RTIR.
+
+This extension is named RT-Extension-TicketAging.
+
+When you install extension it sets up new global custom
+field 'Age' of 'select single' type with several predefined
+values:
+• Active
+• Finished
+• Dead
+• Extinct
+• Destroyed
+
+Extension comes with scrip 'rt-aging' which could be ran from
+command line or by cron.
+
+Each age has several properties: search condition, filter and
+action.
+
+Search condition is used to find ticket candidates for age
+changing. Filter is a function that could be used to filter
+collection by conditions that couldn't be impressed as search
+query. To the tickets left in collection custom action applied
+if it's defined, otherwise only age is changed.
+
+=== NOTES
+
+* age is changed without transaction writing in order to avoid
+  changing properties of the ticket.
+
+== DEFAULT SETUP
+
+=== Finished
+
+A ticket is finished when it and its children have been resolved.
+No special action applied to the tickets. 
+
+== Dead
+
+When a ticket and its children are finished for a set period
+of time(by default 2 months) then it is Dead. LastUpdated property
+of tickets is used to determine starting date of the period. Tickets
+of the dead age are available for generic search operations,
+except special requirement to hide these tickets from "whois"
+tool in the RTIR extension.
+
+== Extinct
+
+After a set period of time of being dead(by default 12 month since last
+update of ticket ) a ticket is extinct. Extinct tickets wont, by default
+show up in any searches. Unless the search has an explicit 'include extinct
+tickets' criterion is added to the search.
+
+* RT filters tickets with 'deleted' status from search results,
+  so to hide tickets from searches we could use this status when age
+  of a ticket is 'Extinct'. In order to allow user to find these
+  tickets we can unhide them when search condition
+  has 'CF.{Age} = "Extinct"'.
+
+== Destroyed
+
+After a set period of time of being extinct(by default 24 month since last
+update of ticket) a ticket is destroyed, but only if all linked tickets are
+of extinct age too. Destroyed tickets are deleted from the RT DB and saved
+as backups on a disk in files. Destroyed tickets are not available anymore
+throught any RT interfaces.
+
+Backup files can be used to restore information into data base.
+Location of the files as file name template are configurable from config. Files
+can be moved or deleted. Destroyed tickets are no more available from
+web or command line interface.
+
+Also, script could be executed with '--prune-backups <days>' switch to cleanup
+files which are old.
+
+== Format of the backup files
+
+Default file name template is "sqldump-<timestamp>-<XXXX>.sql".
+
+Each file contain SQL commands that insert or update prviously deleted/changed
+records back into RT DB. For example with MySQL you can run next command to
+restore backup:
+
+    $> mysql -u root -p rt3db < sqldump-20050316T134556-0000.sql
+
+= CONFIGURATION
+
+== List of ages
+
+List of available ages are configured via list of values of
+the 'Age' custom field. System administrator may delete
+values to disable fields. Adding new values activates new
+age, but if name is not default you have to configure
+conditions and actions for the age.
+
+== Ages map
+
+User may define 'TicketAgingMap' config option to override
+default options. This option is hash with age values as keys
+and hash references as values with configuration.
+
+Next options are available:
+
+  AgeName => {
+    Condition => {
+      CallbackPre => code reference,
+      SQL => string or code reference,
+      CallbackPost => code reference,
+      Filter => code reference,
+    },
+    Action => code reference,
+  },
+  AnotherAge => {
+    ...
+  }
+
+=== SQL
+
+Tickets' SQL query you can setup to choose tickets for age switching.
+
+For example:
+  SQL => "LastUpdated < '-2 months'"
+  SQL => "Status = 'resolved'"
+
+You may also provide code reference, function should return SQL string.
+Function called with one named parametr 'Age'.
+
+=== CallbackPre and CallbackPost
+
+Two code references that could be used to set up properties of the collection
+object. CallbackPre is called before any action is applied to collection
+(even before it's limit by search condition) and CallbackPost is called
+just before actual walking throught collection.
+
+Functions are called with two named arguments: Age and Collection. Callbacks
+must return true on success or (undef, $error_message) otherwise.
+
+=== Filter
+
+Code reference can be used to filter tickets in collection.
+Takes Age, Collection and Object as named arguments and must
+return false if ticket should be skipped or true value otherwise.
+
+=== Action
+
+Code reference that can be used to change ticket and it's properties
+just before setting new age value.
+
+== Other config options
+
+=== TicketAgingFilenameTemplate
+
+Use it to setup template of file names used for backups while
+tickets deletion.
+

Added: RT-Extension-TicketAging/etc/initialdata
==============================================================================
--- (empty file)
+++ RT-Extension-TicketAging/etc/initialdata	Tue Sep  5 17:27:43 2006
@@ -0,0 +1,21 @@
+
+
+ at CustomFields = (
+    {
+        Name        => 'Age',
+        Type        => 'SelectSingle',
+        Queue       => 0,
+        Disabled    => 0,
+        Description => 'Ticket Age',
+        Values      => [
+            { Name => "Active",     SortOrder => 1 },
+            { Name => "Finished",   SortOrder => 2 },
+            { Name => "Dead",       SortOrder => 3 },
+            { Name => "Extinct",    SortOrder => 4 },
+            { Name => "Fossilized", SortOrder => 5 },
+            { Name => "Destroyed",  SortOrder => 6 },
+        ],
+    },
+);
+
+1;

Added: RT-Extension-TicketAging/inc/Module/AutoInstall.pm
==============================================================================
--- (empty file)
+++ RT-Extension-TicketAging/inc/Module/AutoInstall.pm	Tue Sep  5 17:27:43 2006
@@ -0,0 +1,768 @@
+#line 1
+package Module::AutoInstall;
+
+use strict;
+use Cwd                 ();
+use ExtUtils::MakeMaker ();
+
+use vars qw{$VERSION};
+BEGIN {
+	$VERSION = '1.03';
+}
+
+# special map on pre-defined feature sets
+my %FeatureMap = (
+    ''      => 'Core Features',    # XXX: deprecated
+    '-core' => 'Core Features',
+);
+
+# various lexical flags
+my ( @Missing, @Existing,  %DisabledTests, $UnderCPAN,     $HasCPANPLUS );
+my ( $Config,  $CheckOnly, $SkipInstall,   $AcceptDefault, $TestOnly );
+my ( $PostambleActions, $PostambleUsed );
+
+# See if it's a testing or non-interactive session
+_accept_default( $ENV{AUTOMATED_TESTING} or ! -t STDIN ); 
+_init();
+
+sub _accept_default {
+    $AcceptDefault = shift;
+}
+
+sub missing_modules {
+    return @Missing;
+}
+
+sub do_install {
+    __PACKAGE__->install(
+        [
+            $Config
+            ? ( UNIVERSAL::isa( $Config, 'HASH' ) ? %{$Config} : @{$Config} )
+            : ()
+        ],
+        @Missing,
+    );
+}
+
+# initialize various flags, and/or perform install
+sub _init {
+    foreach my $arg (
+        @ARGV,
+        split(
+            /[\s\t]+/,
+            $ENV{PERL_AUTOINSTALL} || $ENV{PERL_EXTUTILS_AUTOINSTALL} || ''
+        )
+      )
+    {
+        if ( $arg =~ /^--config=(.*)$/ ) {
+            $Config = [ split( ',', $1 ) ];
+        }
+        elsif ( $arg =~ /^--installdeps=(.*)$/ ) {
+            __PACKAGE__->install( $Config, @Missing = split( /,/, $1 ) );
+            exit 0;
+        }
+        elsif ( $arg =~ /^--default(?:deps)?$/ ) {
+            $AcceptDefault = 1;
+        }
+        elsif ( $arg =~ /^--check(?:deps)?$/ ) {
+            $CheckOnly = 1;
+        }
+        elsif ( $arg =~ /^--skip(?:deps)?$/ ) {
+            $SkipInstall = 1;
+        }
+        elsif ( $arg =~ /^--test(?:only)?$/ ) {
+            $TestOnly = 1;
+        }
+    }
+}
+
+# overrides MakeMaker's prompt() to automatically accept the default choice
+sub _prompt {
+    goto &ExtUtils::MakeMaker::prompt unless $AcceptDefault;
+
+    my ( $prompt, $default ) = @_;
+    my $y = ( $default =~ /^[Yy]/ );
+
+    print $prompt, ' [', ( $y ? 'Y' : 'y' ), '/', ( $y ? 'n' : 'N' ), '] ';
+    print "$default\n";
+    return $default;
+}
+
+# the workhorse
+sub import {
+    my $class = shift;
+    my @args  = @_ or return;
+    my $core_all;
+
+    print "*** $class version " . $class->VERSION . "\n";
+    print "*** Checking for Perl dependencies...\n";
+
+    my $cwd = Cwd::cwd();
+
+    $Config = [];
+
+    my $maxlen = length(
+        (
+            sort   { length($b) <=> length($a) }
+              grep { /^[^\-]/ }
+              map  {
+                ref($_)
+                  ? ( ( ref($_) eq 'HASH' ) ? keys(%$_) : @{$_} )
+                  : ''
+              }
+              map { +{@args}->{$_} }
+              grep { /^[^\-]/ or /^-core$/i } keys %{ +{@args} }
+        )[0]
+    );
+
+    while ( my ( $feature, $modules ) = splice( @args, 0, 2 ) ) {
+        my ( @required, @tests, @skiptests );
+        my $default  = 1;
+        my $conflict = 0;
+
+        if ( $feature =~ m/^-(\w+)$/ ) {
+            my $option = lc($1);
+
+            # check for a newer version of myself
+            _update_to( $modules, @_ ) and return if $option eq 'version';
+
+            # sets CPAN configuration options
+            $Config = $modules if $option eq 'config';
+
+            # promote every features to core status
+            $core_all = ( $modules =~ /^all$/i ) and next
+              if $option eq 'core';
+
+            next unless $option eq 'core';
+        }
+
+        print "[" . ( $FeatureMap{ lc($feature) } || $feature ) . "]\n";
+
+        $modules = [ %{$modules} ] if UNIVERSAL::isa( $modules, 'HASH' );
+
+        unshift @$modules, -default => &{ shift(@$modules) }
+          if ( ref( $modules->[0] ) eq 'CODE' );    # XXX: bugward combatability
+
+        while ( my ( $mod, $arg ) = splice( @$modules, 0, 2 ) ) {
+            if ( $mod =~ m/^-(\w+)$/ ) {
+                my $option = lc($1);
+
+                $default   = $arg    if ( $option eq 'default' );
+                $conflict  = $arg    if ( $option eq 'conflict' );
+                @tests     = @{$arg} if ( $option eq 'tests' );
+                @skiptests = @{$arg} if ( $option eq 'skiptests' );
+
+                next;
+            }
+
+            printf( "- %-${maxlen}s ...", $mod );
+
+            if ( $arg and $arg =~ /^\D/ ) {
+                unshift @$modules, $arg;
+                $arg = 0;
+            }
+
+            # XXX: check for conflicts and uninstalls(!) them.
+            if (
+                defined( my $cur = _version_check( _load($mod), $arg ||= 0 ) ) )
+            {
+                print "loaded. ($cur" . ( $arg ? " >= $arg" : '' ) . ")\n";
+                push @Existing, $mod => $arg;
+                $DisabledTests{$_} = 1 for map { glob($_) } @skiptests;
+            }
+            else {
+                print "missing." . ( $arg ? " (would need $arg)" : '' ) . "\n";
+                push @required, $mod => $arg;
+            }
+        }
+
+        next unless @required;
+
+        my $mandatory = ( $feature eq '-core' or $core_all );
+
+        if (
+            !$SkipInstall
+            and (
+                $CheckOnly
+                or _prompt(
+                    qq{==> Auto-install the }
+                      . ( @required / 2 )
+                      . ( $mandatory ? ' mandatory' : ' optional' )
+                      . qq{ module(s) from CPAN?},
+                    $default ? 'y' : 'n',
+                ) =~ /^[Yy]/
+            )
+          )
+        {
+            push( @Missing, @required );
+            $DisabledTests{$_} = 1 for map { glob($_) } @skiptests;
+        }
+
+        elsif ( !$SkipInstall
+            and $default
+            and $mandatory
+            and
+            _prompt( qq{==> The module(s) are mandatory! Really skip?}, 'n', )
+            =~ /^[Nn]/ )
+        {
+            push( @Missing, @required );
+            $DisabledTests{$_} = 1 for map { glob($_) } @skiptests;
+        }
+
+        else {
+            $DisabledTests{$_} = 1 for map { glob($_) } @tests;
+        }
+    }
+
+    $UnderCPAN = _check_lock();    # check for $UnderCPAN
+
+    if ( @Missing and not( $CheckOnly or $UnderCPAN ) ) {
+        require Config;
+        print
+"*** Dependencies will be installed the next time you type '$Config::Config{make}'.\n";
+
+        # make an educated guess of whether we'll need root permission.
+        print "    (You may need to do that as the 'root' user.)\n"
+          if eval '$>';
+    }
+    print "*** $class configuration finished.\n";
+
+    chdir $cwd;
+
+    # import to main::
+    no strict 'refs';
+    *{'main::WriteMakefile'} = \&Write if caller(0) eq 'main';
+}
+
+# Check to see if we are currently running under CPAN.pm and/or CPANPLUS;
+# if we are, then we simply let it taking care of our dependencies
+sub _check_lock {
+    return unless @Missing;
+
+    if ($ENV{PERL5_CPANPLUS_IS_RUNNING}) {
+        print <<'END_MESSAGE';
+
+*** Since we're running under CPANPLUS, I'll just let it take care
+    of the dependency's installation later.
+END_MESSAGE
+        return 1;
+    }
+
+    _load_cpan();
+
+    # Find the CPAN lock-file
+    my $lock = MM->catfile( $CPAN::Config->{cpan_home}, ".lock" );
+    return unless -f $lock;
+
+    # Check the lock
+    local *LOCK;
+    return unless open(LOCK, $lock);
+
+    if (
+            ( $^O eq 'MSWin32' ? _under_cpan() : <LOCK> == getppid() )
+        and ( $CPAN::Config->{prerequisites_policy} || '' ) ne 'ignore'
+    ) {
+        print <<'END_MESSAGE';
+
+*** Since we're running under CPAN, I'll just let it take care
+    of the dependency's installation later.
+END_MESSAGE
+        return 1;
+    }
+
+    close LOCK;
+    return;
+}
+
+sub install {
+    my $class = shift;
+
+    my $i;    # used below to strip leading '-' from config keys
+    my @config = ( map { s/^-// if ++$i; $_ } @{ +shift } );
+
+    my ( @modules, @installed );
+    while ( my ( $pkg, $ver ) = splice( @_, 0, 2 ) ) {
+
+        # grep out those already installed
+        if ( defined( _version_check( _load($pkg), $ver ) ) ) {
+            push @installed, $pkg;
+        }
+        else {
+            push @modules, $pkg, $ver;
+        }
+    }
+
+    return @installed unless @modules;  # nothing to do
+    return @installed if _check_lock(); # defer to the CPAN shell
+
+    print "*** Installing dependencies...\n";
+
+    return unless _connected_to('cpan.org');
+
+    my %args = @config;
+    my %failed;
+    local *FAILED;
+    if ( $args{do_once} and open( FAILED, '.#autoinstall.failed' ) ) {
+        while (<FAILED>) { chomp; $failed{$_}++ }
+        close FAILED;
+
+        my @newmod;
+        while ( my ( $k, $v ) = splice( @modules, 0, 2 ) ) {
+            push @newmod, ( $k => $v ) unless $failed{$k};
+        }
+        @modules = @newmod;
+    }
+
+    if ( _has_cpanplus() ) {
+        _install_cpanplus( \@modules, \@config );
+    } else {
+        _install_cpan( \@modules, \@config );
+    }
+
+    print "*** $class installation finished.\n";
+
+    # see if we have successfully installed them
+    while ( my ( $pkg, $ver ) = splice( @modules, 0, 2 ) ) {
+        if ( defined( _version_check( _load($pkg), $ver ) ) ) {
+            push @installed, $pkg;
+        }
+        elsif ( $args{do_once} and open( FAILED, '>> .#autoinstall.failed' ) ) {
+            print FAILED "$pkg\n";
+        }
+    }
+
+    close FAILED if $args{do_once};
+
+    return @installed;
+}
+
+sub _install_cpanplus {
+    my @modules   = @{ +shift };
+    my @config    = _cpanplus_config( @{ +shift } );
+    my $installed = 0;
+
+    require CPANPLUS::Backend;
+    my $cp   = CPANPLUS::Backend->new;
+    my $conf = $cp->configure_object;
+
+    return unless $conf->can('conf') # 0.05x+ with "sudo" support
+               or _can_write($conf->_get_build('base'));  # 0.04x
+
+    # if we're root, set UNINST=1 to avoid trouble unless user asked for it.
+    my $makeflags = $conf->get_conf('makeflags') || '';
+    if ( UNIVERSAL::isa( $makeflags, 'HASH' ) ) {
+        # 0.03+ uses a hashref here
+        $makeflags->{UNINST} = 1 unless exists $makeflags->{UNINST};
+
+    } else {
+        # 0.02 and below uses a scalar
+        $makeflags = join( ' ', split( ' ', $makeflags ), 'UNINST=1' )
+          if ( $makeflags !~ /\bUNINST\b/ and eval qq{ $> eq '0' } );
+
+    }
+    $conf->set_conf( makeflags => $makeflags );
+    $conf->set_conf( prereqs   => 1 );
+
+    
+
+    while ( my ( $key, $val ) = splice( @config, 0, 2 ) ) {
+        $conf->set_conf( $key, $val );
+    }
+
+    my $modtree = $cp->module_tree;
+    while ( my ( $pkg, $ver ) = splice( @modules, 0, 2 ) ) {
+        print "*** Installing $pkg...\n";
+
+        MY::preinstall( $pkg, $ver ) or next if defined &MY::preinstall;
+
+        my $success;
+        my $obj = $modtree->{$pkg};
+
+        if ( $obj and defined( _version_check( $obj->{version}, $ver ) ) ) {
+            my $pathname = $pkg;
+            $pathname =~ s/::/\\W/;
+
+            foreach my $inc ( grep { m/$pathname.pm/i } keys(%INC) ) {
+                delete $INC{$inc};
+            }
+
+            my $rv = $cp->install( modules => [ $obj->{module} ] );
+
+            if ( $rv and ( $rv->{ $obj->{module} } or $rv->{ok} ) ) {
+                print "*** $pkg successfully installed.\n";
+                $success = 1;
+            } else {
+                print "*** $pkg installation cancelled.\n";
+                $success = 0;
+            }
+
+            $installed += $success;
+        } else {
+            print << ".";
+*** Could not find a version $ver or above for $pkg; skipping.
+.
+        }
+
+        MY::postinstall( $pkg, $ver, $success ) if defined &MY::postinstall;
+    }
+
+    return $installed;
+}
+
+sub _cpanplus_config {
+	my @config = ();
+	while ( @_ ) {
+		my ($key, $value) = (shift(), shift());
+		if ( $key eq 'prerequisites_policy' ) {
+			if ( $value eq 'follow' ) {
+				$value = CPANPLUS::Internals::Constants::PREREQ_INSTALL();
+			} elsif ( $value eq 'ask' ) {
+				$value = CPANPLUS::Internals::Constants::PREREQ_ASK();
+			} elsif ( $value eq 'ignore' ) {
+				$value = CPANPLUS::Internals::Constants::PREREQ_IGNORE();
+			} else {
+				die "*** Cannot convert option $key = '$value' to CPANPLUS version.\n";
+			}
+		} else {
+			die "*** Cannot convert option $key to CPANPLUS version.\n";
+		}
+	}
+	return @config;
+}
+
+sub _install_cpan {
+    my @modules   = @{ +shift };
+    my @config    = @{ +shift };
+    my $installed = 0;
+    my %args;
+
+    _load_cpan();
+    require Config;
+
+    if (CPAN->VERSION < 1.80) {
+        # no "sudo" support, probe for writableness
+        return unless _can_write( MM->catfile( $CPAN::Config->{cpan_home}, 'sources' ) )
+                  and _can_write( $Config::Config{sitelib} );
+    }
+
+    # if we're root, set UNINST=1 to avoid trouble unless user asked for it.
+    my $makeflags = $CPAN::Config->{make_install_arg} || '';
+    $CPAN::Config->{make_install_arg} =
+      join( ' ', split( ' ', $makeflags ), 'UNINST=1' )
+      if ( $makeflags !~ /\bUNINST\b/ and eval qq{ $> eq '0' } );
+
+    # don't show start-up info
+    $CPAN::Config->{inhibit_startup_message} = 1;
+
+    # set additional options
+    while ( my ( $opt, $arg ) = splice( @config, 0, 2 ) ) {
+        ( $args{$opt} = $arg, next )
+          if $opt =~ /^force$/;    # pseudo-option
+        $CPAN::Config->{$opt} = $arg;
+    }
+
+    local $CPAN::Config->{prerequisites_policy} = 'follow';
+
+    while ( my ( $pkg, $ver ) = splice( @modules, 0, 2 ) ) {
+        MY::preinstall( $pkg, $ver ) or next if defined &MY::preinstall;
+
+        print "*** Installing $pkg...\n";
+
+        my $obj     = CPAN::Shell->expand( Module => $pkg );
+        my $success = 0;
+
+        if ( $obj and defined( _version_check( $obj->cpan_version, $ver ) ) ) {
+            my $pathname = $pkg;
+            $pathname =~ s/::/\\W/;
+
+            foreach my $inc ( grep { m/$pathname.pm/i } keys(%INC) ) {
+                delete $INC{$inc};
+            }
+
+            my $rv = $args{force} ? CPAN::Shell->force( install => $pkg )
+                                  : CPAN::Shell->install($pkg);
+            $rv ||= eval {
+                $CPAN::META->instance( 'CPAN::Distribution', $obj->cpan_file, )
+                  ->{install}
+                  if $CPAN::META;
+            };
+
+            if ( $rv eq 'YES' ) {
+                print "*** $pkg successfully installed.\n";
+                $success = 1;
+            }
+            else {
+                print "*** $pkg installation failed.\n";
+                $success = 0;
+            }
+
+            $installed += $success;
+        }
+        else {
+            print << ".";
+*** Could not find a version $ver or above for $pkg; skipping.
+.
+        }
+
+        MY::postinstall( $pkg, $ver, $success ) if defined &MY::postinstall;
+    }
+
+    return $installed;
+}
+
+sub _has_cpanplus {
+    return (
+        $HasCPANPLUS = (
+            $INC{'CPANPLUS/Config.pm'}
+              or _load('CPANPLUS::Shell::Default')
+        )
+    );
+}
+
+# make guesses on whether we're under the CPAN installation directory
+sub _under_cpan {
+    require Cwd;
+    require File::Spec;
+
+    my $cwd  = File::Spec->canonpath( Cwd::cwd() );
+    my $cpan = File::Spec->canonpath( $CPAN::Config->{cpan_home} );
+
+    return ( index( $cwd, $cpan ) > -1 );
+}
+
+sub _update_to {
+    my $class = __PACKAGE__;
+    my $ver   = shift;
+
+    return
+      if defined( _version_check( _load($class), $ver ) );  # no need to upgrade
+
+    if (
+        _prompt( "==> A newer version of $class ($ver) is required. Install?",
+            'y' ) =~ /^[Nn]/
+      )
+    {
+        die "*** Please install $class $ver manually.\n";
+    }
+
+    print << ".";
+*** Trying to fetch it from CPAN...
+.
+
+    # install ourselves
+    _load($class) and return $class->import(@_)
+      if $class->install( [], $class, $ver );
+
+    print << '.'; exit 1;
+
+*** Cannot bootstrap myself. :-( Installation terminated.
+.
+}
+
+# check if we're connected to some host, using inet_aton
+sub _connected_to {
+    my $site = shift;
+
+    return (
+        ( _load('Socket') and Socket::inet_aton($site) ) or _prompt(
+            qq(
+*** Your host cannot resolve the domain name '$site', which
+    probably means the Internet connections are unavailable.
+==> Should we try to install the required module(s) anyway?), 'n'
+          ) =~ /^[Yy]/
+    );
+}
+
+# check if a directory is writable; may create it on demand
+sub _can_write {
+    my $path = shift;
+    mkdir( $path, 0755 ) unless -e $path;
+
+    return 1 if -w $path;
+
+    print << ".";
+*** You are not allowed to write to the directory '$path';
+    the installation may fail due to insufficient permissions.
+.
+
+    if (
+        eval '$>' and lc(`sudo -V`) =~ /version/ and _prompt(
+            qq(
+==> Should we try to re-execute the autoinstall process with 'sudo'?),
+            ((-t STDIN) ? 'y' : 'n')
+        ) =~ /^[Yy]/
+      )
+    {
+
+        # try to bootstrap ourselves from sudo
+        print << ".";
+*** Trying to re-execute the autoinstall process with 'sudo'...
+.
+        my $missing = join( ',', @Missing );
+        my $config = join( ',',
+            UNIVERSAL::isa( $Config, 'HASH' ) ? %{$Config} : @{$Config} )
+          if $Config;
+
+        return
+          unless system( 'sudo', $^X, $0, "--config=$config",
+            "--installdeps=$missing" );
+
+        print << ".";
+*** The 'sudo' command exited with error!  Resuming...
+.
+    }
+
+    return _prompt(
+        qq(
+==> Should we try to install the required module(s) anyway?), 'n'
+    ) =~ /^[Yy]/;
+}
+
+# load a module and return the version it reports
+sub _load {
+    my $mod  = pop;    # class/instance doesn't matter
+    my $file = $mod;
+
+    $file =~ s|::|/|g;
+    $file .= '.pm';
+
+    local $@;
+    return eval { require $file; $mod->VERSION } || ( $@ ? undef: 0 );
+}
+
+# Load CPAN.pm and it's configuration
+sub _load_cpan {
+    return if $CPAN::VERSION;
+    require CPAN;
+    if ( $CPAN::HandleConfig::VERSION ) {
+        # Newer versions of CPAN have a HandleConfig module
+        CPAN::HandleConfig->load;
+    } else {
+    	# Older versions had the load method in Config directly
+        CPAN::Config->load;
+    }
+}
+
+# compare two versions, either use Sort::Versions or plain comparison
+sub _version_check {
+    my ( $cur, $min ) = @_;
+    return unless defined $cur;
+
+    $cur =~ s/\s+$//;
+
+    # check for version numbers that are not in decimal format
+    if ( ref($cur) or ref($min) or $cur =~ /v|\..*\./ or $min =~ /v|\..*\./ ) {
+        if ( ( $version::VERSION or defined( _load('version') )) and
+             version->can('new') 
+            ) {
+
+            # use version.pm if it is installed.
+            return (
+                ( version->new($cur) >= version->new($min) ) ? $cur : undef );
+        }
+        elsif ( $Sort::Versions::VERSION or defined( _load('Sort::Versions') ) )
+        {
+
+            # use Sort::Versions as the sorting algorithm for a.b.c versions
+            return ( ( Sort::Versions::versioncmp( $cur, $min ) != -1 )
+                ? $cur
+                : undef );
+        }
+
+        warn "Cannot reliably compare non-decimal formatted versions.\n"
+          . "Please install version.pm or Sort::Versions.\n";
+    }
+
+    # plain comparison
+    local $^W = 0;    # shuts off 'not numeric' bugs
+    return ( $cur >= $min ? $cur : undef );
+}
+
+# nothing; this usage is deprecated.
+sub main::PREREQ_PM { return {}; }
+
+sub _make_args {
+    my %args = @_;
+
+    $args{PREREQ_PM} = { %{ $args{PREREQ_PM} || {} }, @Existing, @Missing }
+      if $UnderCPAN or $TestOnly;
+
+    if ( $args{EXE_FILES} and -e 'MANIFEST' ) {
+        require ExtUtils::Manifest;
+        my $manifest = ExtUtils::Manifest::maniread('MANIFEST');
+
+        $args{EXE_FILES} =
+          [ grep { exists $manifest->{$_} } @{ $args{EXE_FILES} } ];
+    }
+
+    $args{test}{TESTS} ||= 't/*.t';
+    $args{test}{TESTS} = join( ' ',
+        grep { !exists( $DisabledTests{$_} ) }
+          map { glob($_) } split( /\s+/, $args{test}{TESTS} ) );
+
+    my $missing = join( ',', @Missing );
+    my $config =
+      join( ',', UNIVERSAL::isa( $Config, 'HASH' ) ? %{$Config} : @{$Config} )
+      if $Config;
+
+    $PostambleActions = (
+        $missing
+        ? "\$(PERL) $0 --config=$config --installdeps=$missing"
+        : "\$(NOECHO) \$(NOOP)"
+    );
+
+    return %args;
+}
+
+# a wrapper to ExtUtils::MakeMaker::WriteMakefile
+sub Write {
+    require Carp;
+    Carp::croak "WriteMakefile: Need even number of args" if @_ % 2;
+
+    if ($CheckOnly) {
+        print << ".";
+*** Makefile not written in check-only mode.
+.
+        return;
+    }
+
+    my %args = _make_args(@_);
+
+    no strict 'refs';
+
+    $PostambleUsed = 0;
+    local *MY::postamble = \&postamble unless defined &MY::postamble;
+    ExtUtils::MakeMaker::WriteMakefile(%args);
+
+    print << "." unless $PostambleUsed;
+*** WARNING: Makefile written with customized MY::postamble() without
+    including contents from Module::AutoInstall::postamble() --
+    auto installation features disabled.  Please contact the author.
+.
+
+    return 1;
+}
+
+sub postamble {
+    $PostambleUsed = 1;
+
+    return << ".";
+
+config :: installdeps
+\t\$(NOECHO) \$(NOOP)
+
+checkdeps ::
+\t\$(PERL) $0 --checkdeps
+
+installdeps ::
+\t$PostambleActions
+
+.
+
+}
+
+1;
+
+__END__
+
+#line 1003

Added: RT-Extension-TicketAging/inc/Module/Install.pm
==============================================================================
--- (empty file)
+++ RT-Extension-TicketAging/inc/Module/Install.pm	Tue Sep  5 17:27:43 2006
@@ -0,0 +1,281 @@
+#line 1
+package Module::Install;
+
+# For any maintainers:
+# The load order for Module::Install is a bit magic.
+# It goes something like this...
+#
+# IF ( host has Module::Install installed, creating author mode ) {
+#     1. Makefile.PL calls "use inc::Module::Install"
+#     2. $INC{inc/Module/Install.pm} set to installed version of inc::Module::Install
+#     3. The installed version of inc::Module::Install loads
+#     4. inc::Module::Install calls "require Module::Install"
+#     5. The ./inc/ version of Module::Install loads
+# } ELSE {
+#     1. Makefile.PL calls "use inc::Module::Install"
+#     2. $INC{inc/Module/Install.pm} set to ./inc/ version of Module::Install
+#     3. The ./inc/ version of Module::Install loads
+# }
+
+use 5.004;
+use strict 'vars';
+
+use vars qw{$VERSION};
+BEGIN {
+    # All Module::Install core packages now require synchronised versions.
+    # This will be used to ensure we don't accidentally load old or
+    # different versions of modules.
+    # This is not enforced yet, but will be some time in the next few
+    # releases once we can make sure it won't clash with custom
+    # Module::Install extensions.
+    $VERSION = '0.64';
+}
+
+# Whether or not inc::Module::Install is actually loaded, the
+# $INC{inc/Module/Install.pm} is what will still get set as long as
+# the caller loaded module this in the documented manner.
+# If not set, the caller may NOT have loaded the bundled version, and thus
+# they may not have a MI version that works with the Makefile.PL. This would
+# result in false errors or unexpected behaviour. And we don't want that.
+my $file = join( '/', 'inc', split /::/, __PACKAGE__ ) . '.pm';
+unless ( $INC{$file} ) {
+    die <<"END_DIE";
+Please invoke ${\__PACKAGE__} with:
+
+    use inc::${\__PACKAGE__};
+
+not:
+
+    use ${\__PACKAGE__};
+
+END_DIE
+}
+
+# If the script that is loading Module::Install is from the future,
+# then make will detect this and cause it to re-run over and over
+# again. This is bad. Rather than taking action to touch it (which
+# is unreliable on some platforms and requires write permissions)
+# for now we should catch this and refuse to run.
+if ( -f $0 and (stat($0))[9] > time ) {
+	die << "END_DIE";
+Your installer $0 has a modification time in the future.
+
+This is known to create infinite loops in make.
+
+Please correct this, then run $0 again.
+
+END_DIE
+}
+
+use Cwd        ();
+use File::Find ();
+use File::Path ();
+use FindBin;
+
+*inc::Module::Install::VERSION = *VERSION;
+ at inc::Module::Install::ISA     = __PACKAGE__;
+
+sub autoload {
+    my $self = shift;
+    my $who  = $self->_caller;
+    my $cwd  = Cwd::cwd();
+    my $sym  = "${who}::AUTOLOAD";
+    $sym->{$cwd} = sub {
+        my $pwd = Cwd::cwd();
+        if ( my $code = $sym->{$pwd} ) {
+            # delegate back to parent dirs
+            goto &$code unless $cwd eq $pwd;
+        }
+        $$sym =~ /([^:]+)$/ or die "Cannot autoload $who - $sym";
+        unshift @_, ($self, $1);
+        goto &{$self->can('call')} unless uc($1) eq $1;
+    };
+}
+
+sub import {
+    my $class = shift;
+    my $self  = $class->new(@_);
+    my $who   = $self->_caller;
+
+    unless ( -f $self->{file} ) {
+        require "$self->{path}/$self->{dispatch}.pm";
+        File::Path::mkpath("$self->{prefix}/$self->{author}");
+        $self->{admin} = "$self->{name}::$self->{dispatch}"->new( _top => $self );
+        $self->{admin}->init;
+        @_ = ($class, _self => $self);
+        goto &{"$self->{name}::import"};
+    }
+
+    *{"${who}::AUTOLOAD"} = $self->autoload;
+    $self->preload;
+
+    # Unregister loader and worker packages so subdirs can use them again
+    delete $INC{"$self->{file}"};
+    delete $INC{"$self->{path}.pm"};
+}
+
+sub preload {
+    my ($self) = @_;
+
+    unless ( $self->{extensions} ) {
+        $self->load_extensions(
+            "$self->{prefix}/$self->{path}", $self
+        );
+    }
+
+    my @exts = @{$self->{extensions}};
+    unless ( @exts ) {
+        my $admin = $self->{admin};
+        @exts = $admin->load_all_extensions;
+    }
+
+    my %seen;
+    foreach my $obj ( @exts ) {
+        while (my ($method, $glob) = each %{ref($obj) . '::'}) {
+            next unless $obj->can($method);
+            next if $method =~ /^_/;
+            next if $method eq uc($method);
+            $seen{$method}++;
+        }
+    }
+
+    my $who = $self->_caller;
+    foreach my $name ( sort keys %seen ) {
+        *{"${who}::$name"} = sub {
+            ${"${who}::AUTOLOAD"} = "${who}::$name";
+            goto &{"${who}::AUTOLOAD"};
+        };
+    }
+}
+
+sub new {
+    my ($class, %args) = @_;
+
+    # ignore the prefix on extension modules built from top level.
+    my $base_path = Cwd::abs_path($FindBin::Bin);
+    unless ( Cwd::abs_path(Cwd::cwd()) eq $base_path ) {
+        delete $args{prefix};
+    }
+
+    return $args{_self} if $args{_self};
+
+    $args{dispatch} ||= 'Admin';
+    $args{prefix}   ||= 'inc';
+    $args{author}   ||= ($^O eq 'VMS' ? '_author' : '.author');
+    $args{bundle}   ||= 'inc/BUNDLES';
+    $args{base}     ||= $base_path;
+    $class =~ s/^\Q$args{prefix}\E:://;
+    $args{name}     ||= $class;
+    $args{version}  ||= $class->VERSION;
+    unless ( $args{path} ) {
+        $args{path}  = $args{name};
+        $args{path}  =~ s!::!/!g;
+    }
+    $args{file}     ||= "$args{base}/$args{prefix}/$args{path}.pm";
+
+    bless( \%args, $class );
+}
+
+sub call {
+	my ($self, $method) = @_;
+	my $obj = $self->load($method) or return;
+        splice(@_, 0, 2, $obj);
+	goto &{$obj->can($method)};
+}
+
+sub load {
+    my ($self, $method) = @_;
+
+    $self->load_extensions(
+        "$self->{prefix}/$self->{path}", $self
+    ) unless $self->{extensions};
+
+    foreach my $obj (@{$self->{extensions}}) {
+        return $obj if $obj->can($method);
+    }
+
+    my $admin = $self->{admin} or die <<"END_DIE";
+The '$method' method does not exist in the '$self->{prefix}' path!
+Please remove the '$self->{prefix}' directory and run $0 again to load it.
+END_DIE
+
+    my $obj = $admin->load($method, 1);
+    push @{$self->{extensions}}, $obj;
+
+    $obj;
+}
+
+sub load_extensions {
+    my ($self, $path, $top) = @_;
+
+    unless ( grep { lc $_ eq lc $self->{prefix} } @INC ) {
+        unshift @INC, $self->{prefix};
+    }
+
+    foreach my $rv ( $self->find_extensions($path) ) {
+        my ($file, $pkg) = @{$rv};
+        next if $self->{pathnames}{$pkg};
+
+        local $@;
+        my $new = eval { require $file; $pkg->can('new') };
+        unless ( $new ) {
+            warn $@ if $@;
+            next;
+        }
+        $self->{pathnames}{$pkg} = delete $INC{$file};
+        push @{$self->{extensions}}, &{$new}($pkg, _top => $top );
+    }
+
+    $self->{extensions} ||= [];
+}
+
+sub find_extensions {
+    my ($self, $path) = @_;
+
+    my @found;
+    File::Find::find( sub {
+        my $file = $File::Find::name;
+        return unless $file =~ m!^\Q$path\E/(.+)\.pm\Z!is;
+        my $subpath = $1;
+        return if lc($subpath) eq lc($self->{dispatch});
+
+        $file = "$self->{path}/$subpath.pm";
+        my $pkg = "$self->{name}::$subpath";
+        $pkg =~ s!/!::!g;
+
+        # If we have a mixed-case package name, assume case has been preserved
+        # correctly.  Otherwise, root through the file to locate the case-preserved
+        # version of the package name.
+        if ( $subpath eq lc($subpath) || $subpath eq uc($subpath) ) {
+            open PKGFILE, "<$subpath.pm" or die "find_extensions: Can't open $subpath.pm: $!";
+            my $in_pod = 0;
+            while ( <PKGFILE> ) {
+                $in_pod = 1 if /^=\w/;
+                $in_pod = 0 if /^=cut/;
+                next if ($in_pod || /^=cut/);  # skip pod text
+                next if /^\s*#/;               # and comments
+                if ( m/^\s*package\s+($pkg)\s*;/i ) {
+                    $pkg = $1;
+                    last;
+                }
+            }
+            close PKGFILE;
+        }
+
+        push @found, [ $file, $pkg ];
+    }, $path ) if -d $path;
+
+    @found;
+}
+
+sub _caller {
+    my $depth = 0;
+    my $call  = caller($depth);
+    while ( $call eq __PACKAGE__ ) {
+        $depth++;
+        $call = caller($depth);
+    }
+    return $call;
+}
+
+1;

Added: RT-Extension-TicketAging/inc/Module/Install/AutoInstall.pm
==============================================================================
--- (empty file)
+++ RT-Extension-TicketAging/inc/Module/Install/AutoInstall.pm	Tue Sep  5 17:27:43 2006
@@ -0,0 +1,61 @@
+#line 1
+package Module::Install::AutoInstall;
+
+use strict;
+use Module::Install::Base;
+
+use vars qw{$VERSION $ISCORE @ISA};
+BEGIN {
+	$VERSION = '0.64';
+	$ISCORE  = 1;
+	@ISA     = qw{Module::Install::Base};
+}
+
+sub AutoInstall { $_[0] }
+
+sub run {
+    my $self = shift;
+    $self->auto_install_now(@_);
+}
+
+sub write {
+    my $self = shift;
+    $self->auto_install(@_);
+}
+
+sub auto_install {
+    my $self = shift;
+    return if $self->{done}++;
+
+    # Flatten array of arrays into a single array
+    my @core = map @$_, map @$_, grep ref,
+               $self->build_requires, $self->requires;
+
+    my @config = @_;
+
+    # We'll need Module::AutoInstall
+    $self->include('Module::AutoInstall');
+    require Module::AutoInstall;
+
+    Module::AutoInstall->import(
+        (@config ? (-config => \@config) : ()),
+        (@core   ? (-core   => \@core)   : ()),
+        $self->features,
+    );
+
+    $self->makemaker_args( Module::AutoInstall::_make_args() );
+
+    my $class = ref($self);
+    $self->postamble(
+        "# --- $class section:\n" .
+        Module::AutoInstall::postamble()
+    );
+}
+
+sub auto_install_now {
+    my $self = shift;
+    $self->auto_install(@_);
+    Module::AutoInstall::do_install();
+}
+
+1;

Added: RT-Extension-TicketAging/inc/Module/Install/Base.pm
==============================================================================
--- (empty file)
+++ RT-Extension-TicketAging/inc/Module/Install/Base.pm	Tue Sep  5 17:27:43 2006
@@ -0,0 +1,70 @@
+#line 1
+package Module::Install::Base;
+
+$VERSION = '0.64';
+
+# Suspend handler for "redefined" warnings
+BEGIN {
+	my $w = $SIG{__WARN__};
+	$SIG{__WARN__} = sub { $w };
+}
+
+### This is the ONLY module that shouldn't have strict on
+# use strict;
+
+#line 41
+
+sub new {
+    my ($class, %args) = @_;
+
+    foreach my $method ( qw(call load) ) {
+        *{"$class\::$method"} = sub {
+            shift()->_top->$method(@_);
+        } unless defined &{"$class\::$method"};
+    }
+
+    bless( \%args, $class );
+}
+
+#line 61
+
+sub AUTOLOAD {
+    my $self = shift;
+    local $@;
+    my $autoload = eval { $self->_top->autoload } or return;
+    goto &$autoload;
+}
+
+#line 76
+
+sub _top { $_[0]->{_top} }
+
+#line 89
+
+sub admin {
+    $_[0]->_top->{admin} or Module::Install::Base::FakeAdmin->new;
+}
+
+sub is_admin {
+    $_[0]->admin->VERSION;
+}
+
+sub DESTROY {}
+
+package Module::Install::Base::FakeAdmin;
+
+my $Fake;
+sub new { $Fake ||= bless(\@_, $_[0]) }
+
+sub AUTOLOAD {}
+
+sub DESTROY {}
+
+# Restore warning handler
+BEGIN {
+	$SIG{__WARN__} = $SIG{__WARN__}->();
+}
+
+1;
+
+#line 138

Added: RT-Extension-TicketAging/inc/Module/Install/Can.pm
==============================================================================
--- (empty file)
+++ RT-Extension-TicketAging/inc/Module/Install/Can.pm	Tue Sep  5 17:27:43 2006
@@ -0,0 +1,82 @@
+#line 1
+package Module::Install::Can;
+
+use strict;
+use Module::Install::Base;
+use Config ();
+### This adds a 5.005 Perl version dependency.
+### This is a bug and will be fixed.
+use File::Spec ();
+use ExtUtils::MakeMaker ();
+
+use vars qw{$VERSION $ISCORE @ISA};
+BEGIN {
+	$VERSION = '0.64';
+	$ISCORE  = 1;
+	@ISA     = qw{Module::Install::Base};
+}
+
+# check if we can load some module
+### Upgrade this to not have to load the module if possible
+sub can_use {
+	my ($self, $mod, $ver) = @_;
+	$mod =~ s{::|\\}{/}g;
+	$mod .= '.pm' unless $mod =~ /\.pm$/i;
+
+	my $pkg = $mod;
+	$pkg =~ s{/}{::}g;
+	$pkg =~ s{\.pm$}{}i;
+
+	local $@;
+	eval { require $mod; $pkg->VERSION($ver || 0); 1 };
+}
+
+# check if we can run some command
+sub can_run {
+	my ($self, $cmd) = @_;
+
+	my $_cmd = $cmd;
+	return $_cmd if (-x $_cmd or $_cmd = MM->maybe_command($_cmd));
+
+	for my $dir ((split /$Config::Config{path_sep}/, $ENV{PATH}), '.') {
+		my $abs = File::Spec->catfile($dir, $_[1]);
+		return $abs if (-x $abs or $abs = MM->maybe_command($abs));
+	}
+
+	return;
+}
+
+# can we locate a (the) C compiler
+sub can_cc {
+	my $self   = shift;
+	my @chunks = split(/ /, $Config::Config{cc}) or return;
+
+	# $Config{cc} may contain args; try to find out the program part
+	while (@chunks) {
+		return $self->can_run("@chunks") || (pop(@chunks), next);
+	}
+
+	return;
+}
+
+# Fix Cygwin bug on maybe_command();
+if ( $^O eq 'cygwin' ) {
+	require ExtUtils::MM_Cygwin;
+	require ExtUtils::MM_Win32;
+	if ( ! defined(&ExtUtils::MM_Cygwin::maybe_command) ) {
+		*ExtUtils::MM_Cygwin::maybe_command = sub {
+			my ($self, $file) = @_;
+			if ($file =~ m{^/cygdrive/}i and ExtUtils::MM_Win32->can('maybe_command')) {
+				ExtUtils::MM_Win32->maybe_command($file);
+			} else {
+				ExtUtils::MM_Unix->maybe_command($file);
+			}
+		}
+	}
+}
+
+1;
+
+__END__
+
+#line 157

Added: RT-Extension-TicketAging/inc/Module/Install/Fetch.pm
==============================================================================
--- (empty file)
+++ RT-Extension-TicketAging/inc/Module/Install/Fetch.pm	Tue Sep  5 17:27:43 2006
@@ -0,0 +1,93 @@
+#line 1
+package Module::Install::Fetch;
+
+use strict;
+use Module::Install::Base;
+
+use vars qw{$VERSION $ISCORE @ISA};
+BEGIN {
+	$VERSION = '0.64';
+	$ISCORE  = 1;
+	@ISA     = qw{Module::Install::Base};
+}
+
+sub get_file {
+    my ($self, %args) = @_;
+    my ($scheme, $host, $path, $file) = 
+        $args{url} =~ m|^(\w+)://([^/]+)(.+)/(.+)| or return;
+
+    if ( $scheme eq 'http' and ! eval { require LWP::Simple; 1 } ) {
+        $args{url} = $args{ftp_url}
+            or (warn("LWP support unavailable!\n"), return);
+        ($scheme, $host, $path, $file) = 
+            $args{url} =~ m|^(\w+)://([^/]+)(.+)/(.+)| or return;
+    }
+
+    $|++;
+    print "Fetching '$file' from $host... ";
+
+    unless (eval { require Socket; Socket::inet_aton($host) }) {
+        warn "'$host' resolve failed!\n";
+        return;
+    }
+
+    return unless $scheme eq 'ftp' or $scheme eq 'http';
+
+    require Cwd;
+    my $dir = Cwd::getcwd();
+    chdir $args{local_dir} or return if exists $args{local_dir};
+
+    if (eval { require LWP::Simple; 1 }) {
+        LWP::Simple::mirror($args{url}, $file);
+    }
+    elsif (eval { require Net::FTP; 1 }) { eval {
+        # use Net::FTP to get past firewall
+        my $ftp = Net::FTP->new($host, Passive => 1, Timeout => 600);
+        $ftp->login("anonymous", 'anonymous at example.com');
+        $ftp->cwd($path);
+        $ftp->binary;
+        $ftp->get($file) or (warn("$!\n"), return);
+        $ftp->quit;
+    } }
+    elsif (my $ftp = $self->can_run('ftp')) { eval {
+        # no Net::FTP, fallback to ftp.exe
+        require FileHandle;
+        my $fh = FileHandle->new;
+
+        local $SIG{CHLD} = 'IGNORE';
+        unless ($fh->open("|$ftp -n")) {
+            warn "Couldn't open ftp: $!\n";
+            chdir $dir; return;
+        }
+
+        my @dialog = split(/\n/, <<"END_FTP");
+open $host
+user anonymous anonymous\@example.com
+cd $path
+binary
+get $file $file
+quit
+END_FTP
+        foreach (@dialog) { $fh->print("$_\n") }
+        $fh->close;
+    } }
+    else {
+        warn "No working 'ftp' program available!\n";
+        chdir $dir; return;
+    }
+
+    unless (-f $file) {
+        warn "Fetching failed: $@\n";
+        chdir $dir; return;
+    }
+
+    return if exists $args{size} and -s $file != $args{size};
+    system($args{run}) if exists $args{run};
+    unlink($file) if $args{remove};
+
+    print(((!exists $args{check_for} or -e $args{check_for})
+        ? "done!" : "failed! ($!)"), "\n");
+    chdir $dir; return !$?;
+}
+
+1;

Added: RT-Extension-TicketAging/inc/Module/Install/Include.pm
==============================================================================
--- (empty file)
+++ RT-Extension-TicketAging/inc/Module/Install/Include.pm	Tue Sep  5 17:27:43 2006
@@ -0,0 +1,34 @@
+#line 1
+package Module::Install::Include;
+
+use strict;
+use Module::Install::Base;
+
+use vars qw{$VERSION $ISCORE @ISA};
+BEGIN {
+	$VERSION = '0.64';
+	$ISCORE  = 1;
+	@ISA     = qw{Module::Install::Base};
+}
+
+sub include {
+	shift()->admin->include(@_);
+}
+
+sub include_deps {
+	shift()->admin->include_deps(@_);
+}
+
+sub auto_include {
+	shift()->admin->auto_include(@_);
+}
+
+sub auto_include_deps {
+	shift()->admin->auto_include_deps(@_);
+}
+
+sub auto_include_dependent_dists {
+	shift()->admin->auto_include_dependent_dists(@_);
+}
+
+1;

Added: RT-Extension-TicketAging/inc/Module/Install/Makefile.pm
==============================================================================
--- (empty file)
+++ RT-Extension-TicketAging/inc/Module/Install/Makefile.pm	Tue Sep  5 17:27:43 2006
@@ -0,0 +1,208 @@
+#line 1
+package Module::Install::Makefile;
+
+use strict 'vars';
+use Module::Install::Base;
+use ExtUtils::MakeMaker ();
+
+use vars qw{$VERSION $ISCORE @ISA};
+BEGIN {
+	$VERSION = '0.64';
+	$ISCORE  = 1;
+	@ISA     = qw{Module::Install::Base};
+}
+
+sub Makefile { $_[0] }
+
+my %seen = ();
+
+sub prompt {
+    shift;
+
+    # Infinite loop protection
+    my @c = caller();
+    if ( ++$seen{"$c[1]|$c[2]|$_[0]"} > 3 ) {
+        die "Caught an potential prompt infinite loop ($c[1]|$c[2]|$_[0])";
+    }
+
+    # In automated testing, always use defaults
+    if ( $ENV{AUTOMATED_TESTING} and ! $ENV{PERL_MM_USE_DEFAULT} ) {
+        local $ENV{PERL_MM_USE_DEFAULT} = 1;
+        goto &ExtUtils::MakeMaker::prompt;
+    } else {
+        goto &ExtUtils::MakeMaker::prompt;
+    }
+}
+
+sub makemaker_args {
+    my $self = shift;
+    my $args = ($self->{makemaker_args} ||= {});
+    %$args = ( %$args, @_ ) if @_;
+    $args;
+}
+
+# For mm args that take multiple space-seperated args,
+# append an argument to the current list.
+sub makemaker_append {
+    my $self = shift;
+    my $name = shift;
+    my $args = $self->makemaker_args;
+    $args->{name} = defined $args->{$name}
+    	? join( ' ', $args->{name}, @_ )
+    	: join( ' ', @_ );
+}
+
+sub build_subdirs {
+    my $self    = shift;
+    my $subdirs = $self->makemaker_args->{DIR} ||= [];
+    for my $subdir (@_) {
+        push @$subdirs, $subdir;
+    }
+}
+
+sub clean_files {
+    my $self  = shift;
+    my $clean = $self->makemaker_args->{clean} ||= {};
+    %$clean = (
+        %$clean, 
+        FILES => join(' ', grep length, $clean->{FILES}, @_),
+    );
+}
+
+sub realclean_files {
+    my $self  = shift;
+    my $realclean = $self->makemaker_args->{realclean} ||= {};
+    %$realclean = (
+        %$realclean, 
+        FILES => join(' ', grep length, $realclean->{FILES}, @_),
+    );
+}
+
+sub libs {
+    my $self = shift;
+    my $libs = ref $_[0] ? shift : [ shift ];
+    $self->makemaker_args( LIBS => $libs );
+}
+
+sub inc {
+    my $self = shift;
+    $self->makemaker_args( INC => shift );
+}
+
+sub write {
+    my $self = shift;
+    die "&Makefile->write() takes no arguments\n" if @_;
+
+    my $args = $self->makemaker_args;
+    $args->{DISTNAME} = $self->name;
+    $args->{NAME}     = $self->module_name || $self->name || $self->determine_NAME($args);
+    $args->{VERSION}  = $self->version || $self->determine_VERSION($args);
+    $args->{NAME}     =~ s/-/::/g;
+    if ( $self->tests ) {
+        $args->{test} = { TESTS => $self->tests };
+    }
+    if ($] >= 5.005) {
+        $args->{ABSTRACT} = $self->abstract;
+        $args->{AUTHOR}   = $self->author;
+    }
+    if ( eval($ExtUtils::MakeMaker::VERSION) >= 6.10 ) {
+        $args->{NO_META} = 1;
+    }
+    if ( eval($ExtUtils::MakeMaker::VERSION) > 6.17 and $self->sign ) {
+        $args->{SIGN} = 1;
+    }
+    unless ( $self->is_admin ) {
+        delete $args->{SIGN};
+    }
+
+    # merge both kinds of requires into prereq_pm
+    my $prereq = ($args->{PREREQ_PM} ||= {});
+    %$prereq = ( %$prereq, map { @$_ } map { @$_ } grep $_,
+                 ($self->build_requires, $self->requires) );
+
+    # merge both kinds of requires into prereq_pm
+    my $subdirs = ($args->{DIR} ||= []);
+    if ($self->bundles) {
+        foreach my $bundle (@{ $self->bundles }) {
+            my ($file, $dir) = @$bundle;
+            push @$subdirs, $dir if -d $dir;
+            delete $prereq->{$file};
+        }
+    }
+
+    if ( my $perl_version = $self->perl_version ) {
+        eval "use $perl_version; 1"
+            or die "ERROR: perl: Version $] is installed, "
+                . "but we need version >= $perl_version";
+    }
+
+    my %args = map { ( $_ => $args->{$_} ) } grep {defined($args->{$_})} keys %$args;
+    if ($self->admin->preop) {
+        $args{dist} = $self->admin->preop;
+    }
+
+    my $mm = ExtUtils::MakeMaker::WriteMakefile(%args);
+    $self->fix_up_makefile($mm->{FIRST_MAKEFILE} || 'Makefile');
+}
+
+sub fix_up_makefile {
+    my $self          = shift;
+    my $makefile_name = shift;
+    my $top_class     = ref($self->_top) || '';
+    my $top_version   = $self->_top->VERSION || '';
+
+    my $preamble = $self->preamble 
+        ? "# Preamble by $top_class $top_version\n"
+            . $self->preamble
+        : '';
+    my $postamble = "# Postamble by $top_class $top_version\n"
+        . ($self->postamble || '');
+
+    local *MAKEFILE;
+    open MAKEFILE, "< $makefile_name" or die "fix_up_makefile: Couldn't open $makefile_name: $!";
+    my $makefile = do { local $/; <MAKEFILE> };
+    close MAKEFILE or die $!;
+
+    $makefile =~ s/\b(test_harness\(\$\(TEST_VERBOSE\), )/$1'inc', /;
+    $makefile =~ s/( -I\$\(INST_ARCHLIB\))/ -Iinc$1/g;
+    $makefile =~ s/( "-I\$\(INST_LIB\)")/ "-Iinc"$1/g;
+    $makefile =~ s/^(FULLPERL = .*)/$1 "-Iinc"/m;
+    $makefile =~ s/^(PERL = .*)/$1 "-Iinc"/m;
+
+    # Module::Install will never be used to build the Core Perl
+    # Sometimes PERL_LIB and PERL_ARCHLIB get written anyway, which breaks
+    # PREFIX/PERL5LIB, and thus, install_share. Blank them if they exist
+    $makefile =~ s/^PERL_LIB = .+/PERL_LIB =/m;
+    #$makefile =~ s/^PERL_ARCHLIB = .+/PERL_ARCHLIB =/m;
+
+    # Perl 5.005 mentions PERL_LIB explicitly, so we have to remove that as well.
+    $makefile =~ s/("?)-I\$\(PERL_LIB\)\1//g;
+
+    # XXX - This is currently unused; not sure if it breaks other MM-users
+    # $makefile =~ s/^pm_to_blib\s+:\s+/pm_to_blib :: /mg;
+
+    open  MAKEFILE, "> $makefile_name" or die "fix_up_makefile: Couldn't open $makefile_name: $!";
+    print MAKEFILE  "$preamble$makefile$postamble" or die $!;
+    close MAKEFILE  or die $!;
+
+    1;
+}
+
+sub preamble {
+    my ($self, $text) = @_;
+    $self->{preamble} = $text . $self->{preamble} if defined $text;
+    $self->{preamble};
+}
+
+sub postamble {
+    my ($self, $text) = @_;
+    $self->{postamble} ||= $self->admin->postamble;
+    $self->{postamble} .= $text if defined $text;
+    $self->{postamble}
+}
+
+1;
+
+__END__
+
+#line 334

Added: RT-Extension-TicketAging/inc/Module/Install/Metadata.pm
==============================================================================
--- (empty file)
+++ RT-Extension-TicketAging/inc/Module/Install/Metadata.pm	Tue Sep  5 17:27:43 2006
@@ -0,0 +1,315 @@
+#line 1
+package Module::Install::Metadata;
+
+use strict 'vars';
+use Module::Install::Base;
+
+use vars qw{$VERSION $ISCORE @ISA};
+BEGIN {
+	$VERSION = '0.64';
+	$ISCORE  = 1;
+	@ISA     = qw{Module::Install::Base};
+}
+
+my @scalar_keys = qw{
+    name module_name abstract author version license
+    distribution_type perl_version tests
+};
+
+my @tuple_keys = qw{
+    build_requires requires recommends bundles
+};
+
+sub Meta            { shift        }
+sub Meta_ScalarKeys { @scalar_keys }
+sub Meta_TupleKeys  { @tuple_keys  }
+
+foreach my $key (@scalar_keys) {
+    *$key = sub {
+        my $self = shift;
+        return $self->{values}{$key} if defined wantarray and !@_;
+        $self->{values}{$key} = shift;
+        return $self;
+    };
+}
+
+foreach my $key (@tuple_keys) {
+    *$key = sub {
+        my $self = shift;
+        return $self->{values}{$key} unless @_;
+
+        my @rv;
+        while (@_) {
+            my $module = shift or last;
+            my $version = shift || 0;
+            if ( $module eq 'perl' ) {
+                $version =~ s{^(\d+)\.(\d+)\.(\d+)}
+                             {$1 + $2/1_000 + $3/1_000_000}e;
+                $self->perl_version($version);
+                next;
+            }
+            my $rv = [ $module, $version ];
+            push @rv, $rv;
+        }
+        push @{ $self->{values}{$key} }, @rv;
+        @rv;
+    };
+}
+
+sub sign {
+    my $self = shift;
+    return $self->{'values'}{'sign'} if defined wantarray and !@_;
+    $self->{'values'}{'sign'} = ( @_ ? $_[0] : 1 );
+    return $self;
+}
+
+sub dynamic_config {
+	my $self = shift;
+	unless ( @_ ) {
+		warn "You MUST provide an explicit true/false value to dynamic_config, skipping\n";
+		return $self;
+	}
+	$self->{'values'}{'dynamic_config'} = $_[0] ? 1 : 0;
+	return $self;
+}
+
+sub all_from {
+    my ( $self, $file ) = @_;
+
+    unless ( defined($file) ) {
+        my $name = $self->name
+            or die "all_from called with no args without setting name() first";
+        $file = join('/', 'lib', split(/-/, $name)) . '.pm';
+        $file =~ s{.*/}{} unless -e $file;
+        die "all_from: cannot find $file from $name" unless -e $file;
+    }
+
+    $self->version_from($file)      unless $self->version;
+    $self->perl_version_from($file) unless $self->perl_version;
+
+    # The remaining probes read from POD sections; if the file
+    # has an accompanying .pod, use that instead
+    my $pod = $file;
+    if ( $pod =~ s/\.pm$/.pod/i and -e $pod ) {
+        $file = $pod;
+    }
+
+    $self->author_from($file)   unless $self->author;
+    $self->license_from($file)  unless $self->license;
+    $self->abstract_from($file) unless $self->abstract;
+}
+
+sub provides {
+    my $self     = shift;
+    my $provides = ( $self->{values}{provides} ||= {} );
+    %$provides = (%$provides, @_) if @_;
+    return $provides;
+}
+
+sub auto_provides {
+    my $self = shift;
+    return $self unless $self->is_admin;
+
+    unless (-e 'MANIFEST') {
+        warn "Cannot deduce auto_provides without a MANIFEST, skipping\n";
+        return $self;
+    }
+
+    # Avoid spurious warnings as we are not checking manifest here.
+
+    local $SIG{__WARN__} = sub {1};
+    require ExtUtils::Manifest;
+    local *ExtUtils::Manifest::manicheck = sub { return };
+
+    require Module::Build;
+    my $build = Module::Build->new(
+        dist_name    => $self->name,
+        dist_version => $self->version,
+        license      => $self->license,
+    );
+    $self->provides(%{ $build->find_dist_packages || {} });
+}
+
+sub feature {
+    my $self     = shift;
+    my $name     = shift;
+    my $features = ( $self->{values}{features} ||= [] );
+
+    my $mods;
+
+    if ( @_ == 1 and ref( $_[0] ) ) {
+        # The user used ->feature like ->features by passing in the second
+        # argument as a reference.  Accomodate for that.
+        $mods = $_[0];
+    } else {
+        $mods = \@_;
+    }
+
+    my $count = 0;
+    push @$features, (
+        $name => [
+            map {
+                ref($_) ? ( ref($_) eq 'HASH' ) ? %$_
+                                                : @$_
+                        : $_
+            } @$mods
+        ]
+    );
+
+    return @$features;
+}
+
+sub features {
+    my $self = shift;
+    while ( my ( $name, $mods ) = splice( @_, 0, 2 ) ) {
+        $self->feature( $name, @$mods );
+    }
+    return $self->{values}->{features}
+    	? @{ $self->{values}->{features} }
+    	: ();
+}
+
+sub no_index {
+    my $self = shift;
+    my $type = shift;
+    push @{ $self->{values}{no_index}{$type} }, @_ if $type;
+    return $self->{values}{no_index};
+}
+
+sub read {
+    my $self = shift;
+    $self->include_deps( 'YAML', 0 );
+
+    require YAML;
+    my $data = YAML::LoadFile('META.yml');
+
+    # Call methods explicitly in case user has already set some values.
+    while ( my ( $key, $value ) = each %$data ) {
+        next unless $self->can($key);
+        if ( ref $value eq 'HASH' ) {
+            while ( my ( $module, $version ) = each %$value ) {
+                $self->can($key)->($self, $module => $version );
+            }
+        }
+        else {
+            $self->can($key)->($self, $value);
+        }
+    }
+    return $self;
+}
+
+sub write {
+    my $self = shift;
+    return $self unless $self->is_admin;
+    $self->admin->write_meta;
+    return $self;
+}
+
+sub version_from {
+    my ( $self, $file ) = @_;
+    require ExtUtils::MM_Unix;
+    $self->version( ExtUtils::MM_Unix->parse_version($file) );
+}
+
+sub abstract_from {
+    my ( $self, $file ) = @_;
+    require ExtUtils::MM_Unix;
+    $self->abstract(
+        bless(
+            { DISTNAME => $self->name },
+            'ExtUtils::MM_Unix'
+        )->parse_abstract($file)
+     );
+}
+
+sub _slurp {
+    my ( $self, $file ) = @_;
+
+    local *FH;
+    open FH, "< $file" or die "Cannot open $file.pod: $!";
+    do { local $/; <FH> };
+}
+
+sub perl_version_from {
+    my ( $self, $file ) = @_;
+
+    if (
+        $self->_slurp($file) =~ m/
+        ^
+        use \s*
+        v?
+        ([\d_\.]+)
+        \s* ;
+    /ixms
+      )
+    {
+        my $v = $1;
+        $v =~ s{_}{}g;
+        $self->perl_version($1);
+    }
+    else {
+        warn "Cannot determine perl version info from $file\n";
+        return;
+    }
+}
+
+sub author_from {
+    my ( $self, $file ) = @_;
+    my $content = $self->_slurp($file);
+    if ($content =~ m/
+        =head \d \s+ (?:authors?)\b \s*
+        ([^\n]*)
+        |
+        =head \d \s+ (?:licen[cs]e|licensing|copyright|legal)\b \s*
+        .*? copyright .*? \d\d\d[\d.]+ \s* (?:\bby\b)? \s*
+        ([^\n]*)
+    /ixms) {
+        my $author = $1 || $2;
+        $author =~ s{E<lt>}{<}g;
+        $author =~ s{E<gt>}{>}g;
+        $self->author($author); 
+    }
+    else {
+        warn "Cannot determine author info from $file\n";
+    }
+}
+
+sub license_from {
+    my ( $self, $file ) = @_;
+
+    if (
+        $self->_slurp($file) =~ m/
+        =head \d \s+
+        (?:licen[cs]e|licensing|copyright|legal)\b
+        (.*?)
+        (=head\\d.*|=cut.*|)
+        \z
+    /ixms
+      )
+    {
+        my $license_text = $1;
+        my @phrases      = (
+            'under the same (?:terms|license) as perl itself' => 'perl',
+            'GNU public license'                              => 'gpl',
+            'GNU lesser public license'                       => 'gpl',
+            'BSD license'                                     => 'bsd',
+            'Artistic license'                                => 'artistic',
+            'GPL'                                             => 'gpl',
+            'LGPL'                                            => 'lgpl',
+            'BSD'                                             => 'bsd',
+            'Artistic'                                        => 'artistic',
+        );
+        while ( my ( $pattern, $license ) = splice( @phrases, 0, 2 ) ) {
+            $pattern =~ s{\s+}{\\s+}g;
+            if ( $license_text =~ /\b$pattern\b/i ) {
+                $self->license($license);
+                return 1;
+            }
+        }
+    }
+
+    warn "Cannot determine license info from $file\n";
+    return 'unknown';
+}
+
+1;

Added: RT-Extension-TicketAging/inc/Module/Install/RTx.pm
==============================================================================
--- (empty file)
+++ RT-Extension-TicketAging/inc/Module/Install/RTx.pm	Tue Sep  5 17:27:43 2006
@@ -0,0 +1,158 @@
+#line 1
+package Module::Install::RTx;
+use Module::Install::Base; @ISA = qw(Module::Install::Base);
+
+$Module::Install::RTx::VERSION = '0.11';
+
+use strict;
+use FindBin;
+use File::Glob ();
+use File::Basename ();
+
+sub RTx {
+    my ($self, $name) = @_;
+    my $RTx = 'RTx';
+    $RTx = $1 if $name =~ s/^(\w+)-//;
+    my $fname = $name;
+    $fname =~ s!-!/!g;
+
+    $self->name("$RTx-$name")
+        unless $self->name;
+    $self->abstract("RT $name Extension")
+        unless $self->abstract;
+    $self->version_from (-e "$name.pm" ? "$name.pm" : "lib/$RTx/$fname.pm")
+        unless $self->version;
+
+    my @prefixes = (qw(/opt /usr/local /home /usr /sw ));
+    my $prefix = $ENV{PREFIX};
+    @ARGV = grep { /PREFIX=(.*)/ ? (($prefix = $1), 0) : 1 } @ARGV;
+
+    if ($prefix) {
+        $RT::LocalPath = $prefix;
+        $INC{'RT.pm'} = "$RT::LocalPath/lib/RT.pm";
+    }
+    else {
+        local @INC = (
+            @INC,
+            $ENV{RTHOME} ? ($ENV{RTHOME}, "$ENV{RTHOME}/lib") : (),
+            map {( "$_/rt3/lib", "$_/lib/rt3", "$_/lib" )} grep $_, @prefixes
+        );
+        until ( eval { require RT; $RT::LocalPath } ) {
+            warn "Cannot find the location of RT.pm that defines \$RT::LocalPath in: @INC\n";
+            $_ = $self->prompt("Path to your RT.pm:") or exit;
+            push @INC, $_, "$_/rt3/lib", "$_/lib/rt3", "$_/lib";
+        }
+    }
+
+    my $lib_path = File::Basename::dirname($INC{'RT.pm'});
+    print "Using RT configurations from $INC{'RT.pm'}:\n";
+
+    $RT::LocalVarPath	||= $RT::VarPath;
+    $RT::LocalPoPath	||= $RT::LocalLexiconPath;
+    $RT::LocalHtmlPath	||= $RT::MasonComponentRoot;
+
+    my %path;
+    my $with_subdirs = $ENV{WITH_SUBDIRS};
+    @ARGV = grep { /WITH_SUBDIRS=(.*)/ ? (($with_subdirs = $1), 0) : 1 } @ARGV;
+    my %subdirs = map { $_ => 1 } split(/\s*,\s*/, $with_subdirs);
+
+    foreach (qw(bin etc html po sbin var)) {
+        next unless -d "$FindBin::Bin/$_";
+        next if %subdirs and !$subdirs{$_};
+        $self->no_index( directory => $_ );
+
+        no strict 'refs';
+        my $varname = "RT::Local" . ucfirst($_) . "Path";
+        $path{$_} = ${$varname} || "$RT::LocalPath/$_";
+    }
+
+    $path{$_} .= "/$name" for grep $path{$_}, qw(etc po var);
+    my $args = join(', ', map "q($_)", %path);
+    $path{lib} = "$RT::LocalPath/lib" unless %subdirs and !$subdirs{'lib'};
+    print "./$_\t=> $path{$_}\n" for sort keys %path;
+
+    if (my @dirs = map { (-D => $_) } grep $path{$_}, qw(bin html sbin)) {
+        my @po = map { (-o => $_) } grep -f, File::Glob::bsd_glob("po/*.po");
+        $self->postamble(<< ".") if @po;
+lexicons ::
+\t\$(NOECHO) \$(PERL) -MLocale::Maketext::Extract::Run=xgettext -e \"xgettext(qw(@dirs @po))\"
+.
+    }
+
+    my $postamble = << ".";
+install ::
+\t\$(NOECHO) \$(PERL) -MExtUtils::Install -e \"install({$args})\"
+.
+
+    if ($path{var} and -d $RT::MasonDataDir) {
+        my ($uid, $gid) = (stat($RT::MasonDataDir))[4, 5];
+        $postamble .= << ".";
+\t\$(NOECHO) chown -R $uid:$gid $path{var}
+.
+    }
+
+    my %has_etc;
+    if (File::Glob::bsd_glob("$FindBin::Bin/etc/schema.*")) {
+        # got schema, load factory module
+        $has_etc{schema}++;
+        $self->load('RTxFactory');
+        $self->postamble(<< ".");
+factory ::
+\t\$(NOECHO) \$(PERL) -Ilib -I"$lib_path" -Minc::Module::Install -e"RTxFactory(qw($RTx $name))"
+
+dropdb ::
+\t\$(NOECHO) \$(PERL) -Ilib -I"$lib_path" -Minc::Module::Install -e"RTxFactory(qw($RTx $name drop))"
+
+.
+    }
+    if (File::Glob::bsd_glob("$FindBin::Bin/etc/acl.*")) {
+        $has_etc{acl}++;
+    }
+    if (-e 'etc/initialdata') {
+        $has_etc{initialdata}++;
+    }
+
+    $self->postamble("$postamble\n");
+    if (%subdirs and !$subdirs{'lib'}) {
+        $self->makemaker_args(
+            PM => { "" => "" },
+        )
+    }
+    else {
+        $self->makemaker_args( INSTALLSITELIB => "$RT::LocalPath/lib" );
+    }
+
+    if (%has_etc) {
+        $self->load('RTxInitDB');
+        print "For first-time installation, type 'make initdb'.\n";
+        my $initdb = '';
+        $initdb .= <<"." if $has_etc{schema};
+\t\$(NOECHO) \$(PERL) -Ilib -I"$lib_path" -Minc::Module::Install -e"RTxInitDB(qw(schema))"
+.
+        $initdb .= <<"." if $has_etc{acl};
+\t\$(NOECHO) \$(PERL) -Ilib -I"$lib_path" -Minc::Module::Install -e"RTxInitDB(qw(acl))"
+.
+        $initdb .= <<"." if $has_etc{initialdata};
+\t\$(NOECHO) \$(PERL) -Ilib -I"$lib_path" -Minc::Module::Install -e"RTxInitDB(qw(insert))"
+.
+        $self->postamble("initdb ::\n$initdb\n");
+        $self->postamble("initialize-database ::\n$initdb\n");
+    }
+}
+
+sub RTxInit {
+    unshift @INC, substr(delete($INC{'RT.pm'}), 0, -5) if $INC{'RT.pm'};
+    require RT;
+    RT::LoadConfig();
+    RT::ConnectToDatabase();
+
+    die "Cannot load RT" unless $RT::Handle and $RT::DatabaseType;
+}
+
+1;
+
+__END__
+
+#line 220
+
+#line 241

Added: RT-Extension-TicketAging/inc/Module/Install/RTx/Factory.pm
==============================================================================
--- (empty file)
+++ RT-Extension-TicketAging/inc/Module/Install/RTx/Factory.pm	Tue Sep  5 17:27:43 2006
@@ -0,0 +1,483 @@
+#line 1
+package Module::Install::RTx::Factory;
+use Module::Install::Base; @ISA = qw(Module::Install::Base);
+
+use strict;
+use File::Basename ();
+
+sub RTxInitDB {
+    my ($self, $action) = @_;
+
+    unshift @INC, substr(delete($INC{'RT.pm'}), 0, -5) if $INC{'RT.pm'};
+
+    require RT;
+    unshift @INC, "$RT::LocalPath/lib" if $RT::LocalPath;
+
+    $RT::SbinPath ||= $RT::LocalPath;
+    $RT::SbinPath =~ s/local$/sbin/;
+
+    foreach my $file ($RT::CORE_CONFIG_FILE, $RT::SITE_CONFIG_FILE) {
+        next if !-e $file or -r $file;
+        die "No permission to read $file\n-- please re-run $0 with suitable privileges.\n";
+    }
+
+    RT::LoadConfig();
+
+    my $lib_path = File::Basename::dirname($INC{'RT.pm'});
+    my @args = ("-Ilib");
+    push @args, "-I$RT::LocalPath/lib" if $RT::LocalPath;
+    push @args, (
+        "-I$lib_path",
+        "$RT::SbinPath/rt-setup-database",
+        "--action"      => $action,
+        "--datadir"     => "etc",
+        "--datafile"    => "etc/initialdata",
+        "--dba"         => $RT::DatabaseUser,
+        "--prompt-for-dba-password" => ''
+    );
+    print "$^X @args\n";
+    (system($^X, @args) == 0) or die "...returned with error: $?\n";
+}
+
+sub RTxFactory {
+    my ($self, $RTx, $name, $drop) = @_;
+    my $namespace = "$RTx\::$name";
+
+    $self->RTxInit;
+
+    my $dbh = $RT::Handle->dbh;
+    # get all tables out of database
+    my @tables = $dbh->tables;
+    my ( %tablemap, %typemap, %modulemap );
+    my $driver = $RT::DatabaseType;
+
+    my $CollectionBaseclass = 'RT::SearchBuilder';
+    my $RecordBaseclass     = 'RT::Record';
+    my $LicenseBlock = << '.';
+# BEGIN LICENSE BLOCK
+# 
+# END LICENSE BLOCK
+.
+    my $Attribution = << '.';
+# Autogenerated by Module::Intall::RTx::Factory
+# WARNING: THIS FILE IS AUTOGENERATED. ALL CHANGES TO THIS FILE WILL BE LOST.  
+# 
+# !! DO NOT EDIT THIS FILE !!
+#
+
+use strict;
+.
+    my $RecordInit = '';
+
+    @tables = map { do { {
+	my $table = $_;
+	$table =~ s/.*\.//g;
+	$table =~ s/\W//g;
+	$table =~ s/^\Q$name\E_//i or next;
+	$table ne 'sessions' or next;
+
+	$table = ucfirst(lc($table));
+	$table =~ s/$_/\u$_/ for qw(field group custom member value);
+	$table =~ s/(?<=Scrip)$_/\u$_/ for qw(action condition);
+	$table =~ s/$_/\U$_/ for qw(Acl);
+	$table = $name . '_' . $table;
+
+	$tablemap{$table}  = $table;
+	$modulemap{$table} = $table;
+	if ( $table =~ /^(.*)s$/ ) {
+	    $tablemap{$1}  = $table;
+	    $modulemap{$1} = $1;
+	}
+	$table;
+    } } } @tables;
+
+    $tablemap{'CreatedBy'} = 'User';
+    $tablemap{'UpdatedBy'} = 'User';
+
+    $typemap{'id'}            = 'ro';
+    $typemap{'Creator'}       = 'auto';
+    $typemap{'Created'}       = 'auto';
+    $typemap{'Updated'}       = 'auto';
+    $typemap{'UpdatedBy'}     = 'auto';
+    $typemap{'LastUpdated'}   = 'auto';
+    $typemap{'LastUpdatedBy'} = 'auto';
+
+    $typemap{lc($_)} = $typemap{$_} for keys %typemap;
+
+    foreach my $table (@tables) {
+	if ($drop) {
+	    $dbh->do("DROP TABLE $table");
+	    $dbh->do("DROP sequence ${table}_id_seq") if $driver eq 'Pg';
+	    $dbh->do("DROP sequence ${table}_seq") if $driver eq 'Oracle';
+	    next;
+	}
+
+	my $tablesingle = $table;
+	$tablesingle =~ s/^\Q$name\E_//i;
+	$tablesingle =~ s/s$//;
+	my $tableplural = $tablesingle . "s";
+
+	if ( $tablesingle eq 'ACL' ) {
+	    $tablesingle = "ACE";
+	    $tableplural = "ACL";
+	}
+
+	my %requirements;
+
+	my $CollectionClassName = $namespace . "::" . $tableplural;
+	my $RecordClassName     = $namespace . "::" . $tablesingle;
+
+	my $path = $namespace;
+	$path =~ s/::/\//g;
+
+	my $RecordClassPath     = $path . "/" . $tablesingle . ".pm";
+	my $CollectionClassPath = $path . "/" . $tableplural . ".pm";
+
+	#create a collection class
+	my $CreateInParams;
+	my $CreateOutParams;
+	my $ClassAccessible = "";
+	my $FieldsPod       = "";
+	my $CreatePod       = "";
+	my $CreateSub       = "";
+	my %fields;
+	my $sth = $dbh->prepare("DESCRIBE $table");
+
+	if ( $driver eq 'Pg' ) {
+	    $sth = $dbh->prepare(<<".");
+  SELECT a.attname, format_type(a.atttypid, a.atttypmod),
+         a.attnotnull, a.atthasdef, a.attnum
+    FROM pg_class c, pg_attribute a
+   WHERE c.relname ILIKE '$table'
+         AND a.attnum > 0
+         AND a.attrelid = c.oid
+ORDER BY a.attnum
+.
+	}
+	elsif ( $driver eq 'mysql' ) {
+	    $sth = $dbh->prepare("DESCRIBE $table");
+	}
+	else {
+	    die "$driver is currently unsupported";
+	}
+
+	$sth->execute;
+
+	while ( my $row = $sth->fetchrow_hashref() ) {
+	    my ( $field, $type, $default );
+	    if ( $driver eq 'Pg' ) {
+
+		$field   = $row->{'attname'};
+		$type    = $row->{'format_type'};
+		$default = $row->{'atthasdef'};
+
+		if ( $default != 0 ) {
+		    my $tth = $dbh->prepare(<<".");
+SELECT substring(d.adsrc for 128)
+  FROM pg_attrdef d, pg_class c
+ WHERE c.relname = 'acct'
+       AND c.oid = d.adrelid
+       AND d.adnum = $row->{'attnum'}
+.
+		    $tth->execute();
+		    my @default = $tth->fetchrow_array;
+		    $default = $default[0];
+		}
+
+	    }
+	    elsif ( $driver eq 'mysql' ) {
+		$field   = $row->{'Field'};
+		$type    = $row->{'Type'};
+		$default = $row->{'Default'};
+	    }
+
+	    $fields{$field} = 1;
+
+	    #generate the 'accessible' datastructure
+
+	    if ( $typemap{$field} eq 'auto' ) {
+		$ClassAccessible .= "        $field => 
+		    {read => 1, auto => 1,";
+	    }
+	    elsif ( $typemap{$field} eq 'ro' ) {
+		$ClassAccessible .= "        $field =>
+		    {read => 1,";
+	    }
+	    else {
+		$ClassAccessible .= "        $field => 
+		    {read => 1, write => 1,";
+
+	    }
+
+	    $ClassAccessible .= " type => '$type', default => '$default'},\n";
+
+	    #generate pod for the accessible fields
+	    $FieldsPod .= $self->_pod(<<".");
+^head2 $field
+
+Returns the current value of $field. 
+(In the database, $field is stored as $type.)
+
+.
+
+	    unless ( $typemap{$field} eq 'auto' || $typemap{$field} eq 'ro' ) {
+		$FieldsPod .= $self->_pod(<<".");
+
+^head2 Set$field VALUE
+
+
+Set $field to VALUE. 
+Returns (1, 'Status message') on success and (0, 'Error Message') on failure.
+(In the database, $field will be stored as a $type.)
+
+.
+	    }
+
+	    $FieldsPod .= $self->_pod(<<".");
+^cut
+
+.
+
+	    if ( $modulemap{$field} ) {
+		$FieldsPod .= $self->_pod(<<".");
+^head2 ${field}Obj
+
+Returns the $modulemap{$field} Object which has the id returned by $field
+
+
+^cut
+
+sub ${field}Obj {
+	my \$self = shift;
+	my \$$field =  ${namespace}::$modulemap{$field}->new(\$self->CurrentUser);
+	\$$field->Load(\$self->__Value('$field'));
+	return(\$$field);
+}
+.
+		$requirements{ $tablemap{$field} } =
+		"use ${namespace}::$modulemap{$field};";
+
+	    }
+
+	    unless ( $typemap{$field} eq 'auto' || $field eq 'id' ) {
+
+		#generate create statement
+		$CreateInParams .= "                $field => '$default',\n";
+		$CreateOutParams .=
+		"                         $field => \$args{'$field'},\n";
+
+		#gerenate pod for the create statement	
+		$CreatePod .= "  $type '$field'";
+		$CreatePod .= " defaults to '$default'" if ($default);
+		$CreatePod .= ".\n";
+
+	    }
+
+	}
+
+	$CreateSub = <<".";
+sub Create {
+    my \$self = shift;
+    my \%args = ( 
+$CreateInParams
+		\@_);
+    \$self->SUPER::Create(
+$CreateOutParams);
+
+}
+.
+	$CreatePod .= "\n=cut\n\n";
+
+	my $CollectionClass = $LicenseBlock . $Attribution . $self->_pod(<<".") . $self->_magic_import($CollectionClassName);
+
+^head1 NAME
+
+$CollectionClassName -- Class Description
+
+^head1 SYNOPSIS
+
+use $CollectionClassName
+
+^head1 DESCRIPTION
+
+
+^head1 METHODS
+
+^cut
+
+package $CollectionClassName;
+
+use $CollectionBaseclass;
+use $RecordClassName;
+
+use vars qw( \@ISA );
+\@ISA= qw($CollectionBaseclass);
+
+
+sub _Init {
+    my \$self = shift;
+    \$self->{'table'} = '$table';
+    \$self->{'primary_key'} = 'id';
+
+.
+
+    if ( $fields{'SortOrder'} ) {
+
+	$CollectionClass .= $self->_pod(<<".");
+
+# By default, order by name
+\$self->OrderBy( ALIAS => 'main',
+		FIELD => 'SortOrder',
+		ORDER => 'ASC');
+.
+    }
+    $CollectionClass .= $self->_pod(<<".");
+    return ( \$self->SUPER::_Init(\@_) );
+}
+
+
+^head2 NewItem
+
+Returns an empty new $RecordClassName item
+
+^cut
+
+sub NewItem {
+    my \$self = shift;
+    return($RecordClassName->new(\$self->CurrentUser));
+}
+.
+
+    my $RecordClassHeader = $Attribution . "
+
+^head1 NAME
+
+$RecordClassName
+
+
+^head1 SYNOPSIS
+
+^head1 DESCRIPTION
+
+^head1 METHODS
+
+^cut
+
+package $RecordClassName;
+use $RecordBaseclass; 
+";
+
+    foreach my $key ( keys %requirements ) {
+	$RecordClassHeader .= $requirements{$key} . "\n";
+    }
+    $RecordClassHeader .= <<".";
+
+use vars qw( \@ISA );
+\@ISA= qw( $RecordBaseclass );
+
+sub _Init {
+my \$self = shift; 
+
+\$self->Table('$table');
+\$self->SUPER::_Init(\@_);
+}
+
+.
+
+    my $RecordClass = $LicenseBlock . $RecordClassHeader . $self->_pod(<<".") . $self->_magic_import($RecordClassName);
+
+$RecordInit
+
+^head2 Create PARAMHASH
+
+Create takes a hash of values and creates a row in the database:
+
+$CreatePod
+
+$CreateSub
+
+$FieldsPod
+
+sub _CoreAccessible {
+    {
+    
+$ClassAccessible
+}
+};
+
+.
+
+	print "About to make $RecordClassPath, $CollectionClassPath\n";
+	`mkdir -p $path`;
+
+	open( RECORD, ">$RecordClassPath" );
+	print RECORD $RecordClass;
+	close(RECORD);
+
+	open( COL, ">$CollectionClassPath" );
+	print COL $CollectionClass;
+	close(COL);
+
+    }
+}
+
+sub _magic_import {
+    my $self = shift;
+    my $class = ref($self) || $self;
+
+    #if (exists \$warnings::{unimport})  {
+    #        no warnings qw(redefine);
+
+    my $path = $class;
+    $path =~ s#::#/#gi;
+
+
+    my $content = $self->_pod(<<".");
+        eval \"require ${class}_Overlay\";
+        if (\$@ && \$@ !~ qr{^Can't locate ${path}_Overlay.pm}) {
+            die \$@;
+        };
+
+        eval \"require ${class}_Vendor\";
+        if (\$@ && \$@ !~ qr{^Can't locate ${path}_Vendor.pm}) {
+            die \$@;
+        };
+
+        eval \"require ${class}_Local\";
+        if (\$@ && \$@ !~ qr{^Can't locate ${path}_Local.pm}) {
+            die \$@;
+        };
+
+
+
+
+^head1 SEE ALSO
+
+This class allows \"overlay\" methods to be placed
+into the following files _Overlay is for a System overlay by the original author,
+_Vendor is for 3rd-party vendor add-ons, while _Local is for site-local customizations.  
+
+These overlay files can contain new subs or subs to replace existing subs in this module.
+
+If you'll be working with perl 5.6.0 or greater, each of these files should begin with the line 
+
+   no warnings qw(redefine);
+
+so that perl does not kick and scream when you redefine a subroutine or variable in your overlay.
+
+${class}_Overlay, ${class}_Vendor, ${class}_Local
+
+^cut
+
+
+1;
+.
+
+    return $content;
+}
+
+sub _pod {
+    my ($self, $text) = @_;
+    $text =~ s/^\^/=/mg;
+    return $text;
+}

Added: RT-Extension-TicketAging/inc/Module/Install/Substitute.pm
==============================================================================
--- (empty file)
+++ RT-Extension-TicketAging/inc/Module/Install/Substitute.pm	Tue Sep  5 17:27:43 2006
@@ -0,0 +1,128 @@
+#line 1
+package Module::Install::Substitute;
+
+use vars qw(@ISA);
+use Module::Install::Base; @ISA = qw(Module::Install::Base);
+
+use strict;
+use warnings;
+
+$Module::Install::Substitute::VERSION = '0.02';
+
+require File::Temp;
+require File::Spec;
+require Cwd;
+
+#line 64
+
+sub substitute
+{
+	my $self = shift;
+	$self->{__subst} = shift;
+	$self->{__option} = {};
+	if( UNIVERSAL::isa( $_[0], 'HASH' ) ) {
+		my $opts = shift;
+		while( my ($k,$v) = each( %$opts ) ) {
+			$self->{__option}->{ lc( $k ) } = $v || '';
+		}
+	}
+	$self->_parse_options;
+
+	my @file = @_;
+	foreach my $f (@file) {
+		$self->_rewrite_file( $f );
+	}
+
+	return;
+}
+
+sub _parse_options
+{
+	my $self = shift;
+	my $cwd = Cwd::getcwd();
+	foreach my $t ( qw(from to) ) {
+        $self->{__option}->{$t} = $cwd unless $self->{__option}->{$t};
+		my $d = $self->{__option}->{$t};
+		die "Couldn't read directory '$d'" unless -d $d && -r _;
+	}
+}
+
+sub _rewrite_file
+{
+	my ($self, $file) = @_;
+	my $source = File::Spec->catfile( $self->{__option}{from}, $file );
+	$source .= $self->{__option}{sufix} if $self->{__option}{sufix};
+	unless( -f $source && -r _ ) {
+		print STDERR "Couldn't find file '$source'\n";
+		return;
+	}
+	my $dest = File::Spec->catfile( $self->{__option}{to}, $file );
+	return $self->__rewrite_file( $source, $dest );
+}
+
+sub __rewrite_file
+{
+	my ($self, $source, $dest) = @_;
+
+	my $mode = (stat($source))[2];
+
+	open my $sfh, "<$source" or die "Couldn't open '$source' for read";
+	print "Open input '$source' file for substitution\n";
+
+	my ($tmpfh, $tmpfname) = File::Temp::tempfile('mi-subst-XXXX', UNLINK => 1);
+	$self->__process_streams( $sfh, $tmpfh, ($source eq $dest)? 1: 0 );
+	close $sfh;
+
+	seek $tmpfh, 0, 0 or die "Couldn't seek in tmp file";
+
+	open my $dfh, ">$dest" or die "Couldn't open '$dest' for write";
+	print "Open output '$dest' file for substitution\n";
+
+	while( <$tmpfh> ) {
+		print $dfh $_;
+	}
+	close $dfh;
+	chmod $mode, $dest or "Couldn't change mode on '$dest'";
+}
+
+sub __process_streams
+{
+	my ($self, $in, $out, $replace) = @_;
+	
+	my @queue = ();
+	my $subst = $self->{'__subst'};
+	my $re_subst = join('|', map {"\Q$_"} keys %{ $subst } );
+
+	while( my $str = <$in> ) {
+		if( $str =~ /^###\s*(before|replace|after)\: ?(.*)$/s ) {
+			my ($action, $nstr) = ($1,$2);
+			$nstr =~ s/\@($re_subst)\@/$subst->{$1}/ge;
+
+			$action = 'before' if !$replace && $action eq 'replace';
+			if( $action eq 'before' ) {
+				die "no line before 'before' action" unless @queue;
+				# overwrite prev line;
+				pop @queue;
+				push @queue, $nstr;
+				push @queue, $str;
+			} elsif( $action eq 'replace' ) {
+				push @queue, $nstr;
+			} elsif( $action eq 'after' ) {
+				push @queue, $str;
+				push @queue, $nstr;
+				# skip one line;
+				<$in>;
+			}
+		} else {
+			push @queue, $str;
+		}
+		while( @queue > 3 ) {
+			print $out shift(@queue);
+		}
+	}
+	while( scalar @queue ) {
+		print $out shift(@queue);
+	}
+}
+
+1;

Added: RT-Extension-TicketAging/inc/Module/Install/Win32.pm
==============================================================================
--- (empty file)
+++ RT-Extension-TicketAging/inc/Module/Install/Win32.pm	Tue Sep  5 17:27:43 2006
@@ -0,0 +1,65 @@
+#line 1
+package Module::Install::Win32;
+
+use strict;
+use Module::Install::Base;
+
+use vars qw{$VERSION $ISCORE @ISA};
+BEGIN {
+	$VERSION = '0.64';
+	$ISCORE  = 1;
+	@ISA     = qw{Module::Install::Base};
+}
+
+# determine if the user needs nmake, and download it if needed
+sub check_nmake {
+	my $self = shift;
+	$self->load('can_run');
+	$self->load('get_file');
+	
+	require Config;
+	return unless (
+		$^O eq 'MSWin32'                     and
+		$Config::Config{make}                and
+		$Config::Config{make} =~ /^nmake\b/i and
+		! $self->can_run('nmake')
+	);
+
+	print "The required 'nmake' executable not found, fetching it...\n";
+
+	require File::Basename;
+	my $rv = $self->get_file(
+		url       => 'http://download.microsoft.com/download/vc15/Patch/1.52/W95/EN-US/Nmake15.exe',
+		ftp_url   => 'ftp://ftp.microsoft.com/Softlib/MSLFILES/Nmake15.exe',
+		local_dir => File::Basename::dirname($^X),
+		size      => 51928,
+		run       => 'Nmake15.exe /o > nul',
+		check_for => 'Nmake.exe',
+		remove    => 1,
+	);
+
+	if (!$rv) {
+        die <<'END_MESSAGE';
+
+-------------------------------------------------------------------------------
+
+Since you are using Microsoft Windows, you will need the 'nmake' utility
+before installation. It's available at:
+
+  http://download.microsoft.com/download/vc15/Patch/1.52/W95/EN-US/Nmake15.exe
+      or
+  ftp://ftp.microsoft.com/Softlib/MSLFILES/Nmake15.exe
+
+Please download the file manually, save it to a directory in %PATH% (e.g.
+C:\WINDOWS\COMMAND\), then launch the MS-DOS command line shell, "cd" to
+that directory, and run "Nmake15.exe" from there; that will create the
+'nmake.exe' file needed by this module.
+
+You may then resume the installation process described in README.
+
+-------------------------------------------------------------------------------
+END_MESSAGE
+	}
+}
+
+1;

Added: RT-Extension-TicketAging/inc/Module/Install/WriteAll.pm
==============================================================================
--- (empty file)
+++ RT-Extension-TicketAging/inc/Module/Install/WriteAll.pm	Tue Sep  5 17:27:43 2006
@@ -0,0 +1,43 @@
+#line 1
+package Module::Install::WriteAll;
+
+use strict;
+use Module::Install::Base;
+
+use vars qw{$VERSION $ISCORE @ISA};
+BEGIN {
+	$VERSION = '0.64';
+	$ISCORE  = 1;
+	@ISA     = qw{Module::Install::Base};
+}
+
+sub WriteAll {
+    my $self = shift;
+    my %args = (
+        meta        => 1,
+        sign        => 0,
+        inline      => 0,
+        check_nmake => 1,
+        @_
+    );
+
+    $self->sign(1)                if $args{sign};
+    $self->Meta->write            if $args{meta};
+    $self->admin->WriteAll(%args) if $self->is_admin;
+
+    if ( $0 =~ /Build.PL$/i ) {
+        $self->Build->write;
+    } else {
+        $self->check_nmake if $args{check_nmake};
+        unless ( $self->makemaker_args->{'PL_FILES'} ) {
+        	$self->makemaker_args( PL_FILES => {} );
+        }
+        if ($args{inline}) {
+            $self->Inline->write;
+        } else {
+            $self->Makefile->write;
+        }
+    }
+}
+
+1;

Added: RT-Extension-TicketAging/lib/RT/Extension/TicketAging.pm
==============================================================================
--- (empty file)
+++ RT-Extension-TicketAging/lib/RT/Extension/TicketAging.pm	Tue Sep  5 17:27:43 2006
@@ -0,0 +1,203 @@
+package RT::Extension::TicketAging;
+
+our $VERSION = '0.04';
+
+sub loc(@) { return $RT::SystemUser->loc(@_) }
+
+my @ages = ();
+sub Ages {
+    return @ages if @ages;
+
+    my $cf = RT::CustomField->new( $RT::SystemUser );
+    $cf->Load('Age');
+    die "Couldn't load the custom field" unless $cf->id;
+    my $values = $cf->Values;
+    while ( my $value = $values->Next ) {
+        push @ages, $value->Name;
+    }
+    return @ages;
+}
+
+our %map = (
+    Active   => { },
+    Finished => {
+        Condition => {
+            SQL => sub {
+                return join ' OR ', map "Status = '$_'",
+                    RT::Queue->InactiveStatusArray;
+            },
+            Filter => sub {
+                my %arg = @_;
+                my $query = join ' OR ', map "Status = '$_'",
+                    $arg{'Object'}->QueueObj->ActiveStatusArray;
+
+                my $id = $arg{'Object'}->id;
+                $query = "( $query ) AND ( MemberOf = $id OR DependedOnBy = $id )";
+                my $tickets = RT::Tickets->new( $RT::SystemUser );
+                $tickets->FromSQL( $query );
+                return !$tickets->Count;
+            },
+        },
+    },
+    Dead => {
+        Condition => {
+            SQL => "LastUpdated < '-2 months'",
+        },
+    },
+    Extinct => {
+        Condition => {
+            SQL => "LastUpdated < '-12 months'",
+        },
+        Action => sub { my %arg = @_; return $arg{'Object'}->__Set( Field => 'Status', Value => 'deleted' ) },
+    },
+    Destroyed  => {
+        Condition => {
+            CallbackPre => sub { my %arg = @_; return $arg{'Collection'}->{'allow_deleted_search'} = 1 },
+            SQL => "Status = 'deleted' AND LastUpdated < '-24 months'",
+            Filter => sub {
+                my %arg = @_;
+                my $id = $arg{'Object'}->id;
+                my $query = "(CF.{Age} IS NULL OR CF.{Age} != 'Extinct') AND Linked = $id";
+                my $tickets = RT::Tickets->new( $RT::SystemUser );
+                $tickets->{'allow_deleted_search'} = 1;
+                $tickets->FromSQL( $query );
+                return !$tickets->Count;
+            },
+        },
+        Action => sub {
+            my %arg = @_;
+
+            require RT::Shredder::Plugin;
+            my $plugin = new RT::Shredder::Plugin;
+            my ($status, $msg) = $plugin->LoadByName('SQLDump');
+            return ($status, $msg) unless $status;
+            ($status, $msg) = $plugin->TestArgs(
+                file_name => RT->Config->Get('TicketAgingFilenameTemplate'),
+            );
+            return ($status, $msg) unless $status;
+
+            require RT::Shredder;
+            my $shredder = new RT::Shredder;
+            $shredder->AddDumpPlugin(
+                Object => $plugin,
+            );
+            $shredder->PutObject( Object => $arg{'Object'} );
+            $shredder->WipeoutAll;
+            return 1;
+        },
+    },
+);
+
+sub PrepareMap {
+    my $self = shift || __PACKAGE__;
+    my %res = %map;
+    my $user_map = RT->Config->Get('TicketAgingMap');
+    if ( $user_map ) {
+        $self->_MergeMaps( \%res, $user_map );
+    }
+    foreach my $age ( $self->Ages ) {
+        my ($status, $msg) = $self->_PrepareMap( \%res, $age );
+        return (undef, $msg) unless $status;
+    }
+    return (\%res);
+}
+
+sub MergeMaps {
+    my ($self, $dst, $src) = @_;
+    my %age = map { $_ => 1 } $self->Ages;
+    foreach my $age ( keys %src ) {
+        next unless $src{ $age };
+        unless ( ref $src->{ $age } eq 'HASH' ) {
+            $RT::Logger->error( "TicketAgingMap -> $age is not a hash reference" );
+            next;
+        }
+        if ( my $cond = $src->{ $age }{'Condition'} and ref $cond eq 'HASH' ) {
+            foreach my $field( qw(CallbackPre SQL CallbackPost Filter) ) {
+                next unless defined $cond->{ $field };
+                unless ( $cond->{$field} ) {
+                    $RT::Logger->info( "$age -> Condition -> $field is disabled due to TicketAgingMap" );
+                    delete $dst->{ $age }{'Codition'}{ $field };
+                    next;
+                }
+                if ( ref $cond->{$field} eq 'CODE' || ( $field eq 'SQL' && !ref $cond->{$field} )) {
+                    $dst->{ $age }{'Codition'}{ $field } = $cond->{$field};
+                    next;
+                }
+                $RT::Logger->info( "TicketAgingMap -> $age -> Condition -> $field has incorrect type" );
+            }
+        }
+        elsif ( $src->{ $age }{'Condition'} ) {
+            $RT::Logger->error( "TicketAgingMap -> $age -> Condition is not a hash reference" );
+        }
+        if ( defined $src->{ $age }{'Action'} ) {
+            unless ( $src->{ $age }{'Action'} ) {
+                $RT::Logger->info( "$age -> Action is disabled due to TicketAgingMap" );
+                delete $dst->{ $age }{'Codition'}{ $field };
+            }
+            elsif ( ref $src->{ $age }{'Action'} eq 'CODE' ) {
+                $dst->{ $age }{'Action'} = $src->{ $age }{'Action'};
+            }
+            else {
+                $RT::Logger->error( "TicketAgingMap -> $age -> Condition is not a code reference" );
+            }
+        }
+    }
+}
+
+sub _PrepareMap {
+    my ($self, $map, $age) = @_;
+
+    unless( $map->{ $age } ) {
+        delete $map->{ $age };
+        return 1;
+    }
+
+    my $condition = $map->{ $age }->{'Condition'}
+        or return 1;
+
+    if ( my $query = $condition->{'SQL'} ) {
+        $condition->{'SQL'} = sub { return "$query" }
+            unless ref $query eq 'CODE';
+    }
+    else {
+        delete $condition->{'SQL'};
+    }
+
+    foreach ( qw(CallbackPre Filter CallbackPost) ) {
+        next unless my $code_ref = $condition->{$_};
+        unless ( ref $code_ref eq 'CODE' ) {
+            return 0, loc "Filter(age [_1]) '[_2]' is not code reference", $age, $filter;
+        }
+    }
+    return 1;
+}
+
+
+our $age_cf_id = 0;
+sub GetAgeCustomFieldId {
+    return $age_cf_id if $age_cf_id;
+    my $cf = RT::CustomField->new( $RT::SystemUser );
+    $cf->Load('Age');
+    return $age_cf_id = $cf->id;
+}
+
+use Hook::LexWrap;
+require RT::Tickets;
+wrap 'RT::Tickets::_CustomFieldLimit',
+    pre => sub {
+        return unless lc($_[3]||'') eq 'extinct'; # trigger only extinct value
+        return unless ($_[2]||'=') =~ /^(?:=|>=|<=)$/; # deal only when op is positive
+        my $field = ({@_[4..($#_-1)]})->{'SUBKEY'} or return;
+        $field =~ s/^{?['"]?|['"]?}?$//g; # strip leading/trailing crap
+        if ( $field =~ /\D/ ) {
+            return unless lc $field eq 'age'; # it's name, but not age
+        } else {
+            GetAgeCustomFieldId() unless $age_cf_id;
+            return unless $age_cf_id == $field;
+        }
+        $_[0]->{'allow_deleted_search'} = 1;
+    };
+$RT::Tickets::dispatch{'CUSTOMFIELD'} = \&RT::Tickets::_CustomFieldLimit;
+
+
+1;

Added: RT-Extension-TicketAging/sbin/rt-aging
==============================================================================
--- (empty file)
+++ RT-Extension-TicketAging/sbin/rt-aging	Tue Sep  5 17:27:43 2006
@@ -0,0 +1,138 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+
+use lib qw(/opt/rt3/local/lib);
+use lib qw(/opt/rt3/lib);
+
+use Getopt::Long;
+
+use RT;
+RT::LoadConfig();
+
+my $debug;
+GetOptions( debug => \$debug );
+RT->Config->Set( LogToScreen => ($debug? 'debug': 'error') );
+RT::Init();
+
+require RT::Extension::TicketAging;
+
+sub loc(@) { RT::Extension::TicketAging::loc(@_) }
+
+my @ages = RT::Extension::TicketAging->Ages();
+my ($map, $msg)  = RT::Extension::TicketAging->PrepareMap();
+unless ( $map ) {
+    $RT::Logger->crit( $msg );
+    exit 1;
+}
+
+foreach my $age ( @ages ) {
+    $RT::Logger->debug( loc "Processing [_1] age...", $age );
+    unless ( $map->{ $age } ) {
+        $RT::Logger->debug( loc "Skipped [_1] age", $age );
+        next;
+    }
+
+    my $query = build_age_candidates_query( $age );
+    $RT::Logger->debug( loc "Query for age '[_1]': [_2]", $age, $query );
+
+    my $tickets = RT::Tickets->new( $RT::SystemUser );
+    if ( my $cb = $map->{ $age }{'Condition'}{'CallbackPre'} ) {
+        my ($status, $msg) = $cb->( Age => $age, Collection => $tickets );
+        unless ( $status ) {
+            $RT::Logger->crit(loc "Pre callback for '[_1]' age failed with error: [_2]", $age, $msg );
+        }
+    }
+    $tickets->FromSQL( $query );
+    if ( my $cb = $map->{ $age }{'Condition'}{'CallbackPost'} ) {
+        my ($status, $msg) = $cb->( Age => $age, Collection => $tickets );
+        unless ( $status ) {
+            $RT::Logger->error(loc "Post callback for '[_1]' age failed with error: [_2]", $age, $msg );
+        }
+    }
+    if ( my $count = $tickets->Count ) {
+        $RT::Logger->debug( loc "Found [_1] tickets for age '[_2]'(not filtered)", $count, $age );
+    } else {
+        $RT::Logger->debug( loc "No tickets of '[_1]' age", $age );
+        next;
+    }
+
+    walk_collection( Collection => $tickets, Age => $age );
+
+    $RT::Logger->debug( loc "Complete" );
+}
+exit 0;
+
+sub walk_collection {
+    my %args = ( Collection => undef, Age => undef, @_ );
+    my $objs = $args{'Collection'};
+    fetch_next( $objs, 1 );
+    while ( my $obj = fetch_next( $objs ) ) {
+        my $filter = $map->{ $args{'Age'} }{'Condition'}{'Filter'};
+        if ( $filter ) {
+            next unless $filter->(
+                Object     => $obj,
+                Collection => $args{'Collection'},
+                Age        => $args{'Age'},
+            );
+        }
+        my ($status, $msg) = apply_action(
+            Object     => $obj,
+            Collection => $args{'Collection'},
+            Age        => $args{'Age'},
+        );
+    }
+}
+
+sub apply_action {
+    my %args = ( Object => undef, Collection => undef, Age => undef, @_ );
+    my $age = $args{'Age'};
+    my $action = $map->{ $age }{'Action'};
+    if ( $action ) {
+        my ($status, $msg) = $action->( %args );
+        return ($status, $msg) unless $status;
+    }
+    return $args{'Object'}->AddCustomFieldValue(
+        Field => 'Age',
+        Value => $age,
+        RecordTransaction => 0,
+    );
+}
+
+use constant PAGE_SIZE => 100;
+sub fetch_next($;$) {
+    my ($objs, $init) = @_;
+    if ( $init ) {
+        $objs->RowsPerPage( PAGE_SIZE );
+        $objs->FirstPage;
+        return;
+    }
+
+    my $obj = $objs->Next;
+    return $obj if $obj;
+    $objs->NextPage;
+    return $objs->Next;
+}
+
+sub build_age_candidates_query {
+    my $age = shift;
+    my $query = '';
+
+    if ( exists $map->{ $age }{'Condition'}{'SQL'} ) {
+        $query = $map->{ $age }{'Condition'}{'SQL'}->( Age => $age ) || '';
+        $query = "( $query )" if $query;
+    }
+
+    my $i = 0;
+    $i++ while $ages[$i] && $ages[$i] ne $age;
+    $i-- while $i && !$map->{ $ages[$i-1] };
+    return joinq( 'AND', $query, ($i? "CF.{Age} = '". $ages[$i-1] ."'": "CF.{Age} IS NULL") );
+}
+
+sub joinq {
+    my ($aggregator, @parts) = @_;
+    return '( '. join( " $aggregator ", grep $_ && !/^\s+$/, @parts ) .' )';
+}
+
+

Added: RT-Extension-TicketAging/t/00.load.t
==============================================================================
--- (empty file)
+++ RT-Extension-TicketAging/t/00.load.t	Tue Sep  5 17:27:43 2006
@@ -0,0 +1,11 @@
+use Test::More tests => 2;
+
+BEGIN { require 't/utils.pl' }
+BEGIN {
+    use_ok( 'RT' );
+    RT::LoadConfig();
+    use_ok( 'RT::Extension::TicketAging' );
+}
+
+diag( "Testing RT::Extension::TicketAging $RT::Extension::TicketAging::VERSION" );
+

Added: RT-Extension-TicketAging/t/01.basics.t
==============================================================================
--- (empty file)
+++ RT-Extension-TicketAging/t/01.basics.t	Tue Sep  5 17:27:43 2006
@@ -0,0 +1,42 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+
+use Test::More qw(no_plan);
+
+BEGIN { require 't/utils.pl' }
+RT::Init();
+
+diag("simle test of the script") if $ENV{'TEST_VERBOSE'};
+{
+    my ($res, $err) = run_exec();
+    ok(!$err, 'no error') or diag $err;
+}
+
+diag("check custom field") if $ENV{'TEST_VERBOSE'};
+{
+    my $cf = RT::CustomField->new( $RT::SystemUser );
+    $cf->LoadByNameAndQueue( Name => 'Age', Queue => 0 );
+    unless ( ok($cf->id, 'custom field exists') ) {
+        diag "Custom Field 'Age' doesn't exist. Most probably you forget to ran `make initdb`\n";
+        exit 1;
+    }
+}
+
+diag("active age") if $ENV{'TEST_VERBOSE'};
+{
+    my $ticket = RT::Ticket->new( $RT::SystemUser );
+    my ($id) = $ticket->Create( Queue => 'General' );
+    ok($id, "created ticket");
+
+    my ($res, $err) = run_exec( debug => 1 );
+    my $ferr = filter_log( $err );
+    ok(!$ferr, 'no error') or diag $err;
+
+    $ticket = RT::Ticket->new( $RT::SystemUser );
+    $ticket->Load( $id );
+    is($ticket->id, $id, 'loaded ticket');
+    is($ticket->FirstCustomFieldValue('Age'), 'Active', 'correct age');
+}
+

Added: RT-Extension-TicketAging/t/02.finished-age.t
==============================================================================
--- (empty file)
+++ RT-Extension-TicketAging/t/02.finished-age.t	Tue Sep  5 17:27:43 2006
@@ -0,0 +1,95 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+
+use Test::More qw(no_plan);
+
+BEGIN { require 't/utils.pl' }
+RT::Init();
+
+diag("finished age") if $ENV{'TEST_VERBOSE'};
+{
+    my $ticket = RT::Ticket->new( $RT::SystemUser );
+    my ($id) = $ticket->Create( Queue => 'General', Status => 'resolved' );
+    ok($id, "created ticket");
+
+    my ($res, $err) = run_exec( debug => 1 );
+    my $ferr = filter_log( $err );
+    ok(!$ferr, 'no error') or diag $err;
+
+    $ticket = RT::Ticket->new( $RT::SystemUser );
+    $ticket->Load( $id );
+    is($ticket->id, $id, 'loaded ticket');
+    is($ticket->FirstCustomFieldValue('Age'), 'Finished', 'correct age');
+}
+
+diag("finished age: child is resolved, parent is not") if $ENV{'TEST_VERBOSE'};
+{
+    my $ticket = RT::Ticket->new( $RT::SystemUser );
+    my ($pid) = $ticket->Create( Queue => 'General' );
+    ok($pid, "created parent ticket");
+
+    $ticket = RT::Ticket->new( $RT::SystemUser );
+    my ($cid) = $ticket->Create( Queue => 'General', Status => 'resolved', MemberOf => $pid );
+    ok($cid, "created child ticket");
+
+    my ($res, $err) = run_exec( debug => 1 );
+    my $ferr = filter_log( $err );
+    ok(!$ferr, 'no error') or diag($err);
+
+    $ticket->Load( $pid );
+    is($ticket->id, $pid, 'loaded ticket');
+    is($ticket->FirstCustomFieldValue('Age'), 'Active', 'correct age');
+
+    $ticket->Load( $cid );
+    is($ticket->id, $cid, 'loaded ticket');
+    is($ticket->FirstCustomFieldValue('Age'), 'Finished', 'correct age');
+}
+
+diag("finished age: parent is resolved while child is not") if $ENV{'TEST_VERBOSE'};
+{
+    my $ticket = RT::Ticket->new( $RT::SystemUser );
+    my ($pid) = $ticket->Create( Queue => 'General', Status => 'resolved' );
+    ok($pid, "created parent ticket");
+
+    $ticket = RT::Ticket->new( $RT::SystemUser );
+    my ($cid) = $ticket->Create( Queue => 'General', MemberOf => $pid );
+    ok($cid, "created child ticket");
+
+    my ($res, $err) = run_exec( debug => 1 );
+    my $ferr = filter_log( $err );
+    ok(!$ferr, 'no error') or diag($err);
+
+    $ticket->Load( $pid );
+    is($ticket->id, $pid, 'loaded ticket');
+    is($ticket->FirstCustomFieldValue('Age'), 'Active', 'correct age');
+
+    $ticket->Load( $cid );
+    is($ticket->id, $cid, 'loaded ticket');
+    is($ticket->FirstCustomFieldValue('Age'), 'Active', 'correct age');
+}
+
+diag("finished age: parent is resolved as all its children") if $ENV{'TEST_VERBOSE'};
+{
+    my $ticket = RT::Ticket->new( $RT::SystemUser );
+    my ($pid) = $ticket->Create( Queue => 'General', Status => 'resolved' );
+    ok($pid, "created parent ticket");
+
+    $ticket = RT::Ticket->new( $RT::SystemUser );
+    my ($cid) = $ticket->Create( Queue => 'General', Status => 'resolved', MemberOf => $pid );
+    ok($cid, "created child ticket");
+
+    my ($res, $err) = run_exec( debug => 1 );
+    my $ferr = filter_log( $err );
+    ok(!$ferr, 'no error') or diag $err;
+
+    $ticket->Load( $pid );
+    is($ticket->id, $pid, 'loaded ticket');
+    is($ticket->FirstCustomFieldValue('Age'), 'Finished', 'correct age');
+
+    $ticket->Load( $cid );
+    is($ticket->id, $cid, 'loaded ticket');
+    is($ticket->FirstCustomFieldValue('Age'), 'Finished', 'correct age');
+}
+

Added: RT-Extension-TicketAging/t/03.dead-age.t
==============================================================================
--- (empty file)
+++ RT-Extension-TicketAging/t/03.dead-age.t	Tue Sep  5 17:27:43 2006
@@ -0,0 +1,93 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+
+use Test::More qw(no_plan);
+
+BEGIN { require 't/utils.pl' }
+RT::Init();
+
+diag("dead age") if $ENV{'TEST_VERBOSE'};
+{
+    my $ticket = RT::Ticket->new( $RT::SystemUser );
+    my ($id) = $ticket->Create( Queue => 'General', Status => 'resolved' );
+    ok($id, "created ticket");
+
+    my $date = $ticket->LastUpdatedObj;
+    $date->AddDays( -70 );
+    $ticket->__Set( Field => 'LastUpdated', Value => $date->ISO );
+    is($ticket->LastUpdated, $date->ISO, 'set date' );
+
+    my ($res, $err) = run_exec( debug => 1 );
+    my $ferr = filter_log( $err );
+    ok(!$ferr, 'no error') or diag $err;
+
+    $ticket = RT::Ticket->new( $RT::SystemUser );
+    $ticket->Load( $id );
+    is($ticket->id, $id, 'loaded ticket');
+    is($ticket->FirstCustomFieldValue('Age'), 'Dead', 'correct age');
+}
+
+diag("dead age: parent is finished while child is not") if $ENV{'TEST_VERBOSE'};
+{
+    my $ticket = RT::Ticket->new( $RT::SystemUser );
+    my ($pid) = $ticket->Create( Queue => 'General', Status => 'resolved' );
+    ok($pid, "created parent ticket");
+
+    my $date = $ticket->LastUpdatedObj;
+    $date->AddDays( -70 );
+    $ticket->__Set( Field => 'LastUpdated', Value => $date->ISO );
+    is($ticket->LastUpdated, $date->ISO, 'set date' );
+
+    $ticket = RT::Ticket->new( $RT::SystemUser );
+    my ($cid) = $ticket->Create( Queue => 'General', MemberOf => $pid );
+    ok($cid, "created child ticket");
+    $ticket->__Set( Field => 'LastUpdated', Value => $date->ISO );
+    is($ticket->LastUpdated, $date->ISO, 'set date' );
+
+    my ($res, $err) = run_exec( debug => 1 );
+    my $ferr = filter_log( $err );
+    ok(!$ferr, 'no error') or diag($err);
+
+    $ticket->Load( $pid );
+    is($ticket->id, $pid, 'loaded ticket');
+    is($ticket->FirstCustomFieldValue('Age'), 'Active', 'correct age');
+
+    $ticket->Load( $cid );
+    is($ticket->id, $cid, 'loaded ticket');
+    is($ticket->FirstCustomFieldValue('Age'), 'Active', 'correct age');
+    is($ticket->LastUpdated, $date->ISO, 'set date' );
+}
+
+diag("dead age: child is finished, but parent is not") if $ENV{'TEST_VERBOSE'};
+{
+    my $ticket = RT::Ticket->new( $RT::SystemUser );
+    my ($pid) = $ticket->Create( Queue => 'General' );
+    ok($pid, "created parent ticket");
+
+    my $date = $ticket->LastUpdatedObj;
+    $date->AddDays( -70 );
+    $ticket->__Set( Field => 'LastUpdated', Value => $date->ISO );
+    is($ticket->LastUpdated, $date->ISO, 'set date' );
+
+    $ticket = RT::Ticket->new( $RT::SystemUser );
+    my ($cid) = $ticket->Create( Queue => 'General', MemberOf => $pid, Status => 'resolved' );
+    ok($cid, "created child ticket");
+    $ticket->__Set( Field => 'LastUpdated', Value => $date->ISO );
+    is($ticket->LastUpdated, $date->ISO, 'set date' );
+
+    my ($res, $err) = run_exec( debug => 1 );
+    my $ferr = filter_log( $err );
+    ok(!$ferr, 'no error') or diag($err);
+
+    $ticket->Load( $pid );
+    is($ticket->id, $pid, 'loaded ticket');
+    is($ticket->FirstCustomFieldValue('Age'), 'Active', 'correct age');
+    is($ticket->LastUpdated, $date->ISO, 'correct date' );
+
+    $ticket->Load( $cid );
+    is($ticket->id, $cid, 'loaded ticket');
+    is($ticket->FirstCustomFieldValue('Age'), 'Dead', 'correct age');
+    is($ticket->LastUpdated, $date->ISO, 'correct date' );
+}

Added: RT-Extension-TicketAging/t/04.extinct-age.t
==============================================================================
--- (empty file)
+++ RT-Extension-TicketAging/t/04.extinct-age.t	Tue Sep  5 17:27:43 2006
@@ -0,0 +1,47 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+
+use Test::More qw(no_plan);
+
+BEGIN { require 't/utils.pl' }
+RT::Init();
+use_ok('RT::Extension::TicketAging');
+
+diag("simle test of the script") if $ENV{'TEST_VERBOSE'};
+{
+    my ($res, $err) = run_exec();
+    ok(!$err, 'no error') or diag("error: $err");
+}
+
+diag("extinct age") if $ENV{'TEST_VERBOSE'};
+{
+    my $ticket = RT::Ticket->new( $RT::SystemUser );
+    my ($id) = $ticket->Create( Queue => 'General', Status => 'resolved' );
+    ok($id, "created ticket");
+
+    my $date = $ticket->LastUpdatedObj;
+    $date->AddDays( -31 * 13 );
+    $ticket->__Set( Field => 'LastUpdated', Value => $date->ISO );
+    is($ticket->LastUpdated, $date->ISO, 'set date');
+
+    my ($res, $err) = run_exec( debug => 1 );
+    my $ferr = filter_log( $err );
+    ok(!$ferr, 'no error') or diag $err;
+
+    $ticket = RT::Ticket->new( $RT::SystemUser );
+    $ticket->Load( $id );
+    is($ticket->id, $id, 'loaded ticket');
+    is($ticket->FirstCustomFieldValue('Age'), 'Extinct', 'correct age');
+    is($ticket->Status, 'deleted', 'correct status');
+
+    diag("extinct age: search") if $ENV{'TEST_VERBOSE'};
+    {
+        my $tickets = RT::Tickets->new( $RT::SystemUser );
+        $tickets->FromSQL("id = $id AND CF.{Age} = 'Extinct'");
+        ok($tickets->Count, "we found ticket even if it's deleted");
+    }
+}
+
+

Added: RT-Extension-TicketAging/t/05.destroyed-age.t
==============================================================================
--- (empty file)
+++ RT-Extension-TicketAging/t/05.destroyed-age.t	Tue Sep  5 17:27:43 2006
@@ -0,0 +1,30 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+
+use Test::More qw(no_plan);
+
+BEGIN { require 't/utils.pl' }
+RT::Init();
+
+diag("destroyed age") if $ENV{'TEST_VERBOSE'};
+{
+    my $ticket = RT::Ticket->new( $RT::SystemUser );
+    my ($id) = $ticket->Create( Queue => 'General', Status => 'resolved' );
+    ok($id, "created ticket");
+
+    my $date = $ticket->LastUpdatedObj;
+    $date->AddDays( -31*24 );
+    $ticket->__Set( Field => 'LastUpdated', Value => $date->ISO );
+    is($ticket->LastUpdated, $date->ISO, 'set date' );
+
+    my ($res, $err) = run_exec( debug => 1 );
+    my $ferr = filter_log( $err );
+    ok(!$ferr, 'no error') or diag $err;
+
+    $ticket = RT::Ticket->new( $RT::SystemUser );
+    $ticket->Load( $id );
+    is($ticket->id, undef, "couldn't load destroyed ticket");
+}
+

Added: RT-Extension-TicketAging/t/utils.pl
==============================================================================
--- (empty file)
+++ RT-Extension-TicketAging/t/utils.pl	Tue Sep  5 17:27:43 2006
@@ -0,0 +1,49 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+
+
+BEGIN {
+### after:     push @INC, qw(@RT_LIB_PATH@);
+    push @INC, qw(/opt/rt3/local/lib /opt/rt3/lib);
+}
+
+use RT;
+RT::LoadConfig();
+
+use IPC::Open3 qw(open3);
+use File::Temp qw(tempfile);
+
+our $exec = 'sbin/rt-aging';
+die "Couldn't find programm '$exec'" unless -f $exec;
+die "'$exec' is not executable" unless -x _;
+
+sub run_exec {
+    my %args = @_;
+    my $cmd = $exec;
+    while ( my ($k,$v) = each %args ) {
+        $cmd .= " --$k '$v'";
+    }
+    local $SIG{'PIPE'} = sub { die "bad" };
+
+    my ($fh_out, $fh_in);
+    my $fh_err = tempfile() or die "Couldn't open tmp file: $!";
+
+    my $pid = open3($fh_in, $fh_out, $fh_err, $cmd);
+    close $fh_in; waitpid $pid, 0;
+    my $result = do { local $/; <$fh_out> };
+    my $error = do { $fh_err->flush; seek $fh_err, 0, 0; local $/; <$fh_err> };
+
+    DBIx::SearchBuilder::Record::Cachable->FlushCache;
+
+    return ($result, $error);
+}
+
+sub filter_log {
+    my $msg = shift;
+    $msg =~ s/^\[[^\]]+\]\s*\[(?:debug|info|warning)\]:.*?$//gms;
+    $msg =~ s/^\s+|\s+$//g;
+    return $msg;
+}
+


More information about the Rt-commit mailing list