[Rt-commit] r4511 - in rtir/branches/1.9-EXPERIMENTAL: html/RTIR/Elements

ruz at bestpractical.com ruz at bestpractical.com
Thu Feb 9 09:13:33 EST 2006


Author: ruz
Date: Thu Feb  9 09:13:22 2006
New Revision: 4511

Modified:
   rtir/branches/1.9-EXPERIMENTAL/   (props changed)
   rtir/branches/1.9-EXPERIMENTAL/html/RTIR/Elements/MakeClicky

Log:
 r682 at cubic-pc:  cubic | 2006-02-09 17:16:24 +0300
  r676 at cubic-pc:  cubic | 2006-02-09 16:49:07 +0300
  * tidy before changes
 


Modified: rtir/branches/1.9-EXPERIMENTAL/html/RTIR/Elements/MakeClicky
==============================================================================
--- rtir/branches/1.9-EXPERIMENTAL/html/RTIR/Elements/MakeClicky	(original)
+++ rtir/branches/1.9-EXPERIMENTAL/html/RTIR/Elements/MakeClicky	Thu Feb  9 09:13:22 2006
@@ -1,139 +1,121 @@
-<%args>
+<%ARGS>
 $url_params => undef
 $content => undef
 $ticket => undef
-</%args>
-<%once>
+</%ARGS>
+<%ONCE>
 use Regexp::Common qw(URI net);
 use URI::URL;
 
 my $web_path = RT->Config->Get('WebPath');
 my $url_params_once;
 my $incident;
-my $left = '\b';
-my $right = '\b';
-#my $left = qr[[\w\b\.\,<(\[]];
-#my $right = qr[[\w\b\.\,>)\]]];
 
 my %cb = (
-   default => sub {
-     my ($type,$value) = @_;
-     return qq{<a href="$web_path/RTIR/Tools/Lookup.html?${url_params_once}q=${value}">$value</a>};
-   },
-   ip => 
-   sub {
-     my ($type,$value) = @_;
-     my $result = qq[<a href="$web_path/RTIR/Tools/Lookup.html?@{[$url_params_once]}type=ip&q=${value}">$value</a>];
-     if ($incident) {
-       $result .= qq[ [<a href="$web_path/RTIR/Create.html?Incident=$incident&Queue=Blocks&IP-Value=$value">Block</a>] ];
-     }
-     return $result;
-   },
-   ipdecimal =>
-   sub {
-     my ($type,$value) = @_;
-     my $i = unpack "L",$value;
-     return $value unless $value > 33554432;
-     my $host = do {
-       my $hostnum = sprintf "%lx", $i;
-       my $a = hex( substr( $hostnum, 0, 2 ) );
-       my $b = hex( substr( $hostnum, 2, 2 ) );
-       my $c = hex( substr( $hostnum, 4, 2 ) );
-       my $d = hex( substr( $hostnum, 6, 2 ) );
-       "$a.$b.$c.$d";
-     };
-   my $result;
-   $result = qq[$value <a href="$web_path/RTIR/Tools/Lookup.html?@{[$url_params_once]}type=ip&q=$host">($host)</a>];
-   if ($incident) {
-      $result .= qq[[<a href="$web_path/RTIR/Create.html?Incident=$incident&Queue=Blocks&IP-Value=$host">Block</a>] ];
-   }
-   return $result;
-   },
-   email =>
-   sub {
-     my ($type,$value) = @_;
-     my ($pre,$post) = split /@/,$value,2;
-     my $result = qq[<a href="$web_path/RTIR/Tools/Lookup.html?@{[$url_params_once]}type=email&q=$value">$value</a> ];
-if ($incident) {
-    if ($r->uri =~ /Lookup.html$/) {
-	$result .= qq[<input type="checkbox" name="Requestorbox-$value" unchecked />];
-    }
-    $result .= qq[[<a href="$web_path/RTIR/Create.html?Incident=$incident&Queue=Investigations&Requestors=$value">Investigate to</a>] ];
-}
-     $result .= qq[<a href="$web_path/RTIR/Tools/Lookup.html?@{[$url_params_once]}type=host&q=$post">($post)</a>];
- },
-   url =>
-   sub {
-     my ($type,$value) = @_;
-     my $uri  = URI::URL->new($value);
-     my $host = $uri->host;
-     return qq[<a target="new" href="$value">$value</a> ].
-       qq[<a href="$web_path/RTIR/Tools/Lookup.html?@{[$url_params_once]}type=host&q=$host">($host)</a>];
-   },
-   noc =>
-   sub {
-     my ($type,$value) = @_;
-     return qq[<a href="$web_path/RTIR/Tools/Lookup.html?@{[$url_params_once]}type=handle&q=$value">$value</a>];
-   },
-   host =>
-   sub {
-     my ($type,$value) = @_;
-     my $result =  qq[<a href="$web_path/RTIR/Tools/Lookup.html?@{[$url_params_once]}type=host&q=$value">$value</a>];
-     return $result;
-   },
-  );
+    default => sub {
+        my ($type,$value) = @_;
+        return qq{<a href="$web_path/RTIR/Tools/Lookup.html?${url_params_once}q=${value}">$value</a>};
+    },
+    ip => sub {
+        my ($type,$value) = @_;
+        my $result = qq[<a href="$web_path/RTIR/Tools/Lookup.html?@{[$url_params_once]}type=ip&q=${value}">$value</a>];
+        if ($incident) {
+            $result .= qq[[<a href="$web_path/RTIR/Create.html?Incident=$incident&Queue=Blocks&IP-Value=$value">Block</a>]];
+        }
+        return $result;
+    },
+    ipdecimal => sub {
+        my ($type,$value) = @_;
+        my $i = unpack "L",$value;
+        return $value unless $value > 33554432;
+
+        my $host = do {
+            my $hostnum = sprintf "%lx", $i;
+            my $a = hex( substr( $hostnum, 0, 2 ) );
+            my $b = hex( substr( $hostnum, 2, 2 ) );
+            my $c = hex( substr( $hostnum, 4, 2 ) );
+            my $d = hex( substr( $hostnum, 6, 2 ) );
+            "$a.$b.$c.$d";
+        };
+        my $result = qq[$value <a href="$web_path/RTIR/Tools/Lookup.html?@{[$url_params_once]}type=ip&q=$host">($host)</a>];
+        if ($incident) {
+            $result .= qq[[<a href="$web_path/RTIR/Create.html?Incident=$incident&Queue=Blocks&IP-Value=$host">Block</a>]];
+        }
+        return $result;
+    },
+    email => sub {
+        my ($type,$value) = @_;
+        my ($pre,$post) = split /@/,$value,2;
+        my $result = qq[<a href="$web_path/RTIR/Tools/Lookup.html?@{[$url_params_once]}type=email&q=$value">$value</a>];
+        if ( $incident ) {
+            if ( $r->uri =~ /Lookup.html$/ ) {
+                $result .= qq[<input type="checkbox" name="Requestorbox-$value" unchecked />];
+            }
+            $result .= qq[[<a href="$web_path/RTIR/Create.html?Incident=$incident&Queue=Investigations&Requestors=$value">Investigate to</a>]];
+        }
+        return $result .qq[<a href="$web_path/RTIR/Tools/Lookup.html?@{[$url_params_once]}type=host&q=$post">($post)</a>];
+    },
+    url => sub {
+        my ($type,$value) = @_;
+        my $uri  = URI::URL->new($value);
+        my $host = $uri->host;
+        return qq[<a target="new" href="$value">$value</a>]
+            .qq[<a href="$web_path/RTIR/Tools/Lookup.html?@{[$url_params_once]}type=host&q=$host">($host)</a>];
+    },
+    noc => sub {
+        my ($type,$value) = @_;
+        return qq[<a href="$web_path/RTIR/Tools/Lookup.html?@{[$url_params_once]}type=handle&q=$value">$value</a>];
+    },
+    host => sub {
+        my ($type,$value) = @_;
+        return qq[<a href="$web_path/RTIR/Tools/Lookup.html?@{[$url_params_once]}type=host&q=$value">$value</a>];
+    },
+);
 
 # key -> [ regexp, callback, _recache ]
-my %types =
-  (
-   Ahttpurl	=> [ $RE{URI}{HTTP}{-keep}{-scheme => 'https?'}, $cb{url}],
-   Bip		=> [ q[\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}], $cb{ip} ],
-   Cipdecimal	=> [ q[\d{8,13}(?!=)], $cb{ipdecimal} ],
-   Demail	=> [ q[(?:mailto:)?[\w\.\+-]+\@[\w\.-]+\.\w{2,3}], $cb{email}],
-   Fdomain	=> [ q[(?:[\w-]+\.)+[A-Za-z]{2,3}], $cb{host} ],
-   GRIPE	=> [ q[(?-i:[A-Z][A-Z0-9-]+)], $cb{noc} ],
-  );
+my %types = (
+    A_httpurl   => [ $RE{URI}{HTTP}{-keep}{-scheme => 'https?'},   $cb{url}],
+    B_ip        => [ q[\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}],        $cb{ip} ],
+    C_ipdecimal => [ q[\d{8,13}(?!=)],                             $cb{ipdecimal} ],
+    D_email     => [ q[(?:mailto:)?[\w\.\+-]+\@[\w\.-]+\.\w{2,3}], $cb{email}],
+    F_domain    => [ q[(?:[\w-]+\.)+[A-Za-z]{2,3}],                $cb{host} ],
+    G_RIPE      => [ q[(?-i:[A-Z][A-Z0-9-]+)],                     $cb{noc} ],
+);
 my @types = sort keys %types;
 
-for my $type (@types) {
-  my $d = $types{$type};
-  $d->[2]  = '^' . $d->[0] . '$';
+foreach ( values %types ) {
+    $_->[2] = '^' . $_->[0] . '$';
+    $_->[1] ||= $cb{default};
 }
 
-my $regexp =
-  join "|",
-  map $left.$_.$right,
-  map $_->[0],
-  map $types{$_},
-  @types;
-
-sub handle {
-  my $what = $1;
-  for my $type (@types) {
-    my $d = $types{$type};
-    if ($what =~ $d->[2]) {
-      my $sub = $d->[1] || $cb{default};
-      return $sub->($type,$what);
+my $regexp = join "|",
+             map '\b'. $types{$_}->[0] .'\b',
+             @types;
+
+my $handle = sub {
+    my $what = $_[0];
+    for my $rec( @types{ @types } ) {
+        return $rec->[1]->( $type, $what ) if $what =~ $rec->[2];
     }
-  }
 }
 
-</%once>
-<%init>
+</%ONCE>
+<%INIT>
 $url_params_once=$ARGS{url_params};
 
 $incident = undef;
-if ($ticket && $ticket->QueueObj->Name eq 'Incidents') {
-  $incident = $ticket->Id;
+if ( $ticket && $ticket->QueueObj->Name eq 'Incidents' ) {
+    $incident = $ticket->Id;
 }
 
-if ($url_params_once && $url_params_once !~ /&$/) {
-        $url_params_once .= "&";
+if ( $url_params_once && $url_params_once !~ /&$/ ) {
+    $url_params_once .= "&";
 }
-for ( $$content =~ s/($regexp)/&handle($1||"")/gsieo ) {1}
-return();
-</%init>
-<%doc>
+while ( $$content =~ s/($regexp)/$handle->( $1 || '' )/gsieo ) {1}
+return;
+
+</%INIT>
+<%DOC>
 # Thoughts:
 
 # 1. Regexp::Common doesn't seem to deal with URL's with user:pass in
@@ -145,7 +127,4 @@
 # over the big text
 
 # 4. Callbacks are cool
-
-
-</%doc>
-
+</%DOC>


More information about the Rt-commit mailing list