lib/URI/Find/Schemeless.pm

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