File Coverage

blib/lib/DBI/ProfileSubs.pm
Criterion Covered Total %
statement 14 15 93.3
branch n/a
condition n/a
subroutine 3 3 100.0
pod 0 1 0.0
total 17 19 89.4


line stmt bran cond sub pod time code
1             package DBI::ProfileSubs;
2              
3             our $VERSION = "0.009396";
4              
5             =head1 NAME
6              
7             DBI::ProfileSubs - Subroutines for dynamic profile Path
8              
9             =head1 SYNOPSIS
10              
11             DBI_PROFILE='&norm_std_n3' prog.pl
12              
13             This is new and still experimental.
14              
15             =head1 TO DO
16              
17             Define come kind of naming convention for the subs.
18              
19             =cut
20              
21 2     2   12 use strict;
  2         5  
  2         60  
22 2     2   10 use warnings;
  2         3  
  2         468  
23              
24              
25             # would be good to refactor these regex into separate subs and find some
26             # way to compose them in various combinations into multiple subs.
27             # Perhaps via AUTOLOAD where \&auto_X_Y_Z creates a sub that does X, Y, and Z.
28             # The final subs always need to be very fast.
29             #
30              
31             sub norm_std_n3 {
32             # my ($h, $method_name) = @_;
33 8     8 0 1247 local $_ = $_;
34              
35 8         34 s/\b\d+\b//g; # 42 ->
36 8         15 s/\b0x[0-9A-Fa-f]+\b//g; # 0xFE ->
37              
38 8         12 s/'.*?'/''/g; # single quoted strings (doesn't handle escapes)
39 8         18 s/".*?"/""/g; # double quoted strings (doesn't handle escapes)
40              
41             # convert names like log20001231 into log
42 8         39 s/([a-z_]+)(\d{3,})\b/${1}/ig;
43              
44             # abbreviate massive "in (...)" statements and similar
45 8         13 s!((\s*<[NS]>\s*,\s*){100,})!sprintf("$2,",length($1)/2)!eg;
  0         0  
46              
47 8         78 return $_;
48             }
49              
50             1;