← Index
NYTProf Performance Profile   « block view • line view • sub view »
For bin/pan_genome_post_analysis
  Run on Fri Mar 27 10:01:31 2015
Reported on Fri Mar 27 10:03:35 2015

Filename/Users/ap13/perl5/lib/perl5/Text/Glob.pm
StatementsExecuted 14 statements in 554µs
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
11112µs24µsText::Glob::::BEGIN@2Text::Glob::BEGIN@2
11110µs32µsText::Glob::::BEGIN@3Text::Glob::BEGIN@3
11110µs55µsText::Glob::::BEGIN@13Text::Glob::BEGIN@13
1119µs76µsText::Glob::::BEGIN@4Text::Glob::BEGIN@4
0000s0sText::Glob::::glob_to_regexText::Glob::glob_to_regex
0000s0sText::Glob::::glob_to_regex_stringText::Glob::glob_to_regex_string
0000s0sText::Glob::::match_globText::Glob::match_glob
Call graph for these subroutines as a Graphviz dot language file.
Line State
ments
Time
on line
Calls Time
in subs
Code
1package Text::Glob;
2222µs235µs
# spent 24µs (12+12) within Text::Glob::BEGIN@2 which was called: # once (12µs+12µs) by File::Find::Rule::BEGIN@6 at line 2
use strict;
# spent 24µs making 1 call to Text::Glob::BEGIN@2 # spent 12µs making 1 call to strict::import
3227µs254µs
# spent 32µs (10+22) within Text::Glob::BEGIN@3 which was called: # once (10µs+22µs) by File::Find::Rule::BEGIN@6 at line 3
use Exporter;
# spent 32µs making 1 call to Text::Glob::BEGIN@3 # spent 22µs making 1 call to Exporter::import
427µs
# spent 76µs (9+67) within Text::Glob::BEGIN@4 which was called: # once (9µs+67µs) by File::Find::Rule::BEGIN@6 at line 5
use vars qw/$VERSION @ISA @EXPORT_OK
5145µs2143µs $strict_leading_dot $strict_wildcard_slash/;
# spent 76µs making 1 call to Text::Glob::BEGIN@4 # spent 67µs making 1 call to vars::import
61700ns$VERSION = '0.09';
718µs@ISA = 'Exporter';
81900ns@EXPORT_OK = qw( glob_to_regex glob_to_regex_string match_glob );
9
101200ns$strict_leading_dot = 1;
111100ns$strict_wildcard_slash = 1;
12
132436µs2100µs
# spent 55µs (10+45) within Text::Glob::BEGIN@13 which was called: # once (10µs+45µs) by File::Find::Rule::BEGIN@6 at line 13
use constant debug => 0;
# spent 55µs making 1 call to Text::Glob::BEGIN@13 # spent 45µs making 1 call to constant::import
14
15sub glob_to_regex {
16 my $glob = shift;
17 my $regex = glob_to_regex_string($glob);
18 return qr/^$regex$/;
19}
20
21sub glob_to_regex_string
22{
23 my $glob = shift;
24 my ($regex, $in_curlies, $escaping);
25 local $_;
26 my $first_byte = 1;
27 for ($glob =~ m/(.)/gs) {
28 if ($first_byte) {
29 if ($strict_leading_dot) {
30 $regex .= '(?=[^\.])' unless $_ eq '.';
31 }
32 $first_byte = 0;
33 }
34 if ($_ eq '/') {
35 $first_byte = 1;
36 }
37 if ($_ eq '.' || $_ eq '(' || $_ eq ')' || $_ eq '|' ||
38 $_ eq '+' || $_ eq '^' || $_ eq '$' || $_ eq '@' || $_ eq '%' ) {
39 $regex .= "\\$_";
40 }
41 elsif ($_ eq '*') {
42 $regex .= $escaping ? "\\*" :
43 $strict_wildcard_slash ? "[^/]*" : ".*";
44 }
45 elsif ($_ eq '?') {
46 $regex .= $escaping ? "\\?" :
47 $strict_wildcard_slash ? "[^/]" : ".";
48 }
49 elsif ($_ eq '{') {
50 $regex .= $escaping ? "\\{" : "(";
51 ++$in_curlies unless $escaping;
52 }
53 elsif ($_ eq '}' && $in_curlies) {
54 $regex .= $escaping ? "}" : ")";
55 --$in_curlies unless $escaping;
56 }
57 elsif ($_ eq ',' && $in_curlies) {
58 $regex .= $escaping ? "," : "|";
59 }
60 elsif ($_ eq "\\") {
61 if ($escaping) {
62 $regex .= "\\\\";
63 $escaping = 0;
64 }
65 else {
66 $escaping = 1;
67 }
68 next;
69 }
70 else {
71 $regex .= $_;
72 $escaping = 0;
73 }
74 $escaping = 0;
75 }
76 print "# $glob $regex\n" if debug;
77
78 return $regex;
79}
80
81sub match_glob {
82 print "# ", join(', ', map { "'$_'" } @_), "\n" if debug;
83 my $glob = shift;
84 my $regex = glob_to_regex $glob;
85 local $_;
86 grep { $_ =~ $regex } @_;
87}
88
8917µs1;
90__END__