File Coverage

blib/lib/URI/Find/Schemeless.pm
Criterion Covered Total %
statement 24 24 100.0
branch 2 4 50.0
condition n/a
subroutine 8 8 100.0
pod 2 2 100.0
total 36 38 94.7


line stmt bran cond sub pod time code
1             # Copyright (c) 2000, 2009 Michael G. Schwern. All rights reserved.
2             # This program is free software; you can redistribute it and/or modify
3             # it under the same terms as Perl itself.
4              
5             package URI::Find::Schemeless;
6              
7 2     2   2676 use strict;
  2         3  
  2         83  
8 2     2   11 use base qw(URI::Find);
  2         5  
  2         634  
9              
10             # base.pm error in 5.005_03 prevents it from loading URI::Find if I'm
11             # required first.
12 2     2   16 use URI::Find ();
  2         2  
  2         48  
13              
14 2     2   10 use vars qw($VERSION);
  2         3  
  2         936  
15             $VERSION = 20140709;
16              
17             my($dnsSet) = '\p{isAlpha}A-Za-z0-9-'; # extended for IDNA domains
18              
19             my($cruftSet) = __PACKAGE__->cruft_set . '<>?}';
20              
21             my($tldRe) = __PACKAGE__->top_level_domain_re;
22              
23             my($uricSet) = __PACKAGE__->uric_set;
24              
25             =head1 NAME
26              
27             URI::Find::Schemeless - Find schemeless URIs in arbitrary text.
28              
29              
30             =head1 SYNOPSIS
31              
32             require URI::Find::Schemeless;
33              
34             my $finder = URI::Find::Schemeless->new(\&callback);
35              
36             The rest is the same as URI::Find.
37              
38              
39             =head1 DESCRIPTION
40              
41             URI::Find finds absolute URIs in plain text with some weak heuristics
42             for finding schemeless URIs. This subclass is for finding things
43             which might be URIs in free text. Things like "www.foo.com" and
44             "lifes.a.bitch.if.you.aint.got.net".
45              
46             The heuristics are such that it hopefully finds a minimum of false
47             positives, but there's no easy way for it know if "COMMAND.COM" refers
48             to a web site or a file.
49              
50             =cut
51              
52             sub schemeless_uri_re {
53 178 50   178 1 604 @_ == 1 || __PACKAGE__->badinvo;
54 178         10745 return qr{
55             # Originally I constrained what couldn't be before the match
56             # like this: don't match email addresses, and don't start
57             # anywhere but at the beginning of a host name
58             # (?
59             # but I switched to saying what can be there after seeing a
60             # false match of "Lite.pm" via "MIME/Lite.pm".
61             (?: ^ | (?<=[\s<>()\{\}\[\]]) )
62             # hostname
63             (?: [$dnsSet]+(?:\.[$dnsSet]+)*\.$tldRe
64             | (?:\d{1,3}\.){3}\d{1,3} ) # not inet_aton() complete
65             (?:
66             (?=[\s\Q$cruftSet\E]) # followed by unrelated thing
67             (?!\.\w) # but don't stop mid foo.xx.bar
68             (?
69             |$ # or end of line
70             (?
71             |/[$uricSet#]* # or slash and URI chars
72             )
73             }x;
74             }
75              
76             =head3 top_level_domain_re
77              
78             my $tld_re = $self->top_level_domain_re;
79              
80             Returns the regex for matching top level DNS domains. The regex shouldn't
81             be anchored, it shouldn't do any capturing matches, and it should make
82             itself ignore case.
83              
84             =cut
85              
86             sub top_level_domain_re {
87 2 50   2 1 11 @_ == 1 || __PACKAGE__->badinvo;
88 2         23 my($self) = shift;
89              
90 2     2   1631 use utf8;
  2         14  
  2         16  
91             # Updated from http://www.iana.org/domains/root/db/ with new TLDs
92 2         124 my $plain = join '|', qw(
93             AERO
94             ARPA
95             ASIA
96             BIZ
97             CAT
98             COM
99             COOP
100             EDU
101             GOV
102             INFO
103             INT
104             JOBS
105             MIL
106             MOBI
107             MUSEUM
108             NAME
109             NET
110             ORG
111             PRO
112             TEL
113             TRAVEL
114             ac
115             academy
116             accountants
117             active
118             actor
119             ad
120             ae
121             aero
122             af
123             ag
124             agency
125             ai
126             airforce
127             al
128             am
129             an
130             ao
131             aq
132             ar
133             archi
134             army
135             arpa
136             as
137             asia
138             associates
139             at
140             attorney
141             au
142             audio
143             autos
144             aw
145             ax
146             axa
147             az
148             ba
149             bar
150             bargains
151             bayern
152             bb
153             bd
154             be
155             beer
156             berlin
157             best
158             bf
159             bg
160             bh
161             bi
162             bid
163             bike
164             bio
165             biz
166             bj
167             bl
168             black
169             blackfriday
170             blue
171             bm
172             bmw
173             bn
174             bo
175             boutique
176             bq
177             br
178             brussels
179             bs
180             bt
181             build
182             builders
183             buzz
184             bv
185             bw
186             by
187             bz
188             bzh
189             ca
190             cab
191             camera
192             camp
193             capetown
194             capital
195             cards
196             care
197             career
198             careers
199             cash
200             cat
201             catering
202             cc
203             cd
204             center
205             ceo
206             cf
207             cg
208             ch
209             cheap
210             christmas
211             church
212             ci
213             citic
214             ck
215             cl
216             claims
217             cleaning
218             clinic
219             clothing
220             club
221             cm
222             cn
223             co
224             codes
225             coffee
226             college
227             cologne
228             com
229             community
230             company
231             computer
232             condos
233             construction
234             consulting
235             contractors
236             cooking
237             cool
238             coop
239             country
240             cr
241             credit
242             creditcard
243             cruises
244             cu
245             cv
246             cw
247             cx
248             cy
249             cz
250             dance
251             dating
252             de
253             degree
254             democrat
255             dental
256             dentist
257             desi
258             diamonds
259             digital
260             directory
261             discount
262             dj
263             dk
264             dm
265             dnp
266             do
267             domains
268             durban
269             dz
270             ec
271             edu
272             education
273             ee
274             eg
275             eh
276             email
277             engineer
278             engineering
279             enterprises
280             equipment
281             er
282             es
283             estate
284             et
285             eu
286             eus
287             events
288             exchange
289             expert
290             exposed
291             fail
292             farm
293             feedback
294             fi
295             finance
296             financial
297             fish
298             fishing
299             fitness
300             fj
301             fk
302             flights
303             florist
304             fm
305             fo
306             foo
307             foundation
308             fr
309             frogans
310             fund
311             furniture
312             futbol
313             ga
314             gal
315             gallery
316             gb
317             gd
318             ge
319             gf
320             gg
321             gh
322             gi
323             gift
324             gives
325             gl
326             glass
327             global
328             globo
329             gm
330             gmo
331             gn
332             gop
333             gov
334             gp
335             gq
336             gr
337             graphics
338             gratis
339             green
340             gripe
341             gs
342             gt
343             gu
344             guide
345             guitars
346             guru
347             gw
348             gy
349             hamburg
350             haus
351             hiphop
352             hiv
353             hk
354             hm
355             hn
356             holdings
357             holiday
358             homes
359             horse
360             host
361             house
362             hr
363             ht
364             hu
365             id
366             ie
367             il
368             im
369             immobilien
370             in
371             industries
372             info
373             ink
374             institute
375             insure
376             int
377             international
378             investments
379             io
380             iq
381             ir
382             is
383             it
384             je
385             jetzt
386             jm
387             jo
388             jobs
389             joburg
390             jp
391             juegos
392             kaufen
393             ke
394             kg
395             kh
396             ki
397             kim
398             kitchen
399             kiwi
400             km
401             kn
402             koeln
403             kp
404             kr
405             kred
406             kw
407             ky
408             kz
409             la
410             land
411             lawyer
412             lb
413             lc
414             lease
415             li
416             life
417             lighting
418             limited
419             limo
420             link
421             lk
422             loans
423             london
424             lotto
425             lr
426             ls
427             lt
428             lu
429             luxe
430             luxury
431             lv
432             ly
433             ma
434             maison
435             management
436             mango
437             market
438             marketing
439             mc
440             md
441             me
442             media
443             meet
444             menu
445             mf
446             mg
447             mh
448             miami
449             mil
450             mini
451             mk
452             ml
453             mm
454             mn
455             mo
456             mobi
457             moda
458             moe
459             monash
460             mortgage
461             moscow
462             motorcycles
463             mp
464             mq
465             mr
466             ms
467             mt
468             mu
469             museum
470             mv
471             mw
472             mx
473             my
474             mz
475             na
476             nagoya
477             name
478             navy
479             nc
480             ne
481             net
482             neustar
483             nf
484             ng
485             nhk
486             ni
487             ninja
488             nl
489             no
490             np
491             nr
492             nu
493             nyc
494             nz
495             okinawa
496             om
497             onl
498             org
499             organic
500             ovh
501             pa
502             paris
503             partners
504             parts
505             pe
506             pf
507             pg
508             ph
509             photo
510             photography
511             photos
512             physio
513             pics
514             pictures
515             pink
516             pk
517             pl
518             plumbing
519             pm
520             pn
521             post
522             pr
523             press
524             pro
525             productions
526             properties
527             ps
528             pt
529             pub
530             pw
531             py
532             qa
533             qpon
534             quebec
535             re
536             recipes
537             red
538             rehab
539             reise
540             reisen
541             ren
542             rentals
543             repair
544             report
545             republican
546             rest
547             reviews
548             rich
549             rio
550             ro
551             rocks
552             rodeo
553             rs
554             ru
555             ruhr
556             rw
557             ryukyu
558             sa
559             saarland
560             sb
561             sc
562             schule
563             scot
564             sd
565             se
566             services
567             sexy
568             sg
569             sh
570             shiksha
571             shoes
572             si
573             singles
574             sj
575             sk
576             sl
577             sm
578             sn
579             so
580             social
581             software
582             sohu
583             solar
584             solutions
585             soy
586             space
587             sr
588             ss
589             st
590             su
591             supplies
592             supply
593             support
594             surf
595             surgery
596             sv
597             sx
598             sy
599             systems
600             sz
601             tattoo
602             tax
603             tc
604             td
605             technology
606             tel
607             tf
608             tg
609             th
610             tienda
611             tips
612             tirol
613             tj
614             tk
615             tl
616             tm
617             tn
618             to
619             today
620             tokyo
621             tools
622             town
623             toys
624             tp
625             tr
626             trade
627             training
628             travel
629             tt
630             tv
631             tw
632             tz
633             ua
634             ug
635             uk
636             um
637             university
638             uno
639             us
640             uy
641             uz
642             va
643             vacations
644             vc
645             ve
646             vegas
647             ventures
648             versicherung
649             vet
650             vg
651             vi
652             viajes
653             villas
654             vision
655             vlaanderen
656             vn
657             vodka
658             vote
659             voting
660             voto
661             voyage
662             vu
663             wang
664             watch
665             webcam
666             website
667             wed
668             wf
669             wien
670             wiki
671             works
672             ws
673             wtc
674             wtf
675             测试
676             परीक्षा
677             集团
678             在线
679             한국
680             ভারত
681             موقع
682             বাংলা
683             公益
684             公司
685             移动
686             我爱你
687             москва
688             испытание
689             қаз
690             онлайн
691             сайт
692             срб
693             테스트
694             орг
695             삼성
696             சிங்கப்பூர்
697             商标
698             商城
699             дети
700             мкд
701             טעסט
702             中文网
703             中信
704             中国
705             中國
706             భారత్
707             ලංකා
708             測試
709             ભારત
710             भारत
711             آزمایشی
712             பரிட்சை
713             संगठन
714             网络
715             укр
716             香港
717             δοκιμή
718             إختبار
719             台湾
720             台灣
721             мон
722             الجزائر
723             عمان
724             ایران
725             امارات
726             بازار
727             پاکستان
728             الاردن
729             بھارت
730             المغرب
731             السعودية
732             سودان
733             مليسيا
734             شبكة
735             გე
736             机构
737             组织机构
738             ไทย
739             سورية
740             рф
741             تونس
742             みんな
743             世界
744             ਭਾਰਤ
745             网址
746             游戏
747             مصر
748             قطر
749             இலங்கை
750             இந்தியா
751             新加坡
752             فلسطين
753             テスト
754             政务
755             xxx
756             xyz
757             yachts
758             ye
759             yokohama
760             yt
761             za
762             zm
763             zone
764             zw
765             );
766            
767 2     2   15 return qr/(?:$plain)/i;
  2         5  
  2         27  
  2         252  
768             }
769              
770             =head1 AUTHOR
771              
772             Original code by Roderick Schertler , adapted by
773             Michael G Schwern .
774              
775             Currently maintained by Roderick Schertler .
776              
777             =head1 SEE ALSO
778              
779             L
780              
781             =cut
782              
783             1;