blib/lib/File/LsColor.pm

filter: Statementstmt 36.7% 32 / 87 Branchbran 4.5% 2 / 44 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 62.5% 10 / 16 Podpod n/a totaltotal 29.6% 45 / 152 CC 26 SCAR 51.9
CC
26
Cov
26%
ls_color
380.0
can_ls_color
12.9
parse_ls_colors
10.1
CRAP 179.0
↑ Summary
1 package File::LsColor;
2 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 BEGIN {
6 3 ▶ use Exporter;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 3 ▶ use vars qw($VERSION @ISA @EXPORT_OK %EXPORT_TAGS);
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 3 ▶ $VERSION = '0.491';
Subroutine BEGIN: called CC=1 SCAR=0.0
10 3 @ISA = qw(Exporter);
11  
12 3 @EXPORT_OK = qw(
13 ls_color
14 ls_color_custom
15 ls_color_default
16 ls_color_internal
17 get_ls_colors
18 can_ls_color
19 ls_color_lookup
20 parse_ls_colors
21 );
22  
23 3 %EXPORT_TAGS = (
24 all => [
25 qw(
26 ls_color ls_color_custom ls_color_default ls_color_internal
27 get_ls_colors can_ls_color ls_color_lookup parse_ls_colors
28 )
29 ],
30 );
31 }
32  
33 # alias for compatibility reasons with File::LsColor prior to 0.300
34 {
35 3 ▶ no warnings 'once';
Subroutine BEGIN: called CC=1 SCAR=0.0
36 *ls_color_lookup = *can_ls_color;
37 }
38  
39 3 ▶use Carp qw(croak);
Subroutine BEGIN: called CC=1 SCAR=0.0
40 3 ▶use Term::ExtendedColor qw(fg);
Subroutine BEGIN: called CC=1 SCAR=0.0
41  
42 my $extracted_ls_colors;
43 my $LS_COLORS = $ENV{LS_COLORS}; # Default
44  
45 #<internal LS_COLORS specification
46 # yes, this is pretty :)
47 # colors from https://github.com/trapd00r/LS_COLORS
48 my $internal_ls_color='
49 bd=38;5;68:ca=38;5;17:cd=38;5;113;1:di=38;5;30:do=38;5;127:ex=38;5;166;1:
50 pi=38;5;126:fi=38;5;253:ln=target:mh=38;5;222;1:or=48;5;196;38;5;232;1:
51 ow=38;5;220;1:sg=48;5;3;38;5;0:su=38;5;220;1;3;100;1:so=38;5;197:
52 st=38;5;232;48;5;30:tw=48;5;235;38;5;139;3:*LS_COLORS=48;5;89;38;5;197;1;3;4;7:
53 *.msi=38;5;039:*.xys=38;5;204:*README=38;5;220;1:*LICENSE=38;5;220;1:
54 *COPYING=38;5;220;1:*INSTALL=38;5;220;1:*COPYRIGHT=38;5;220;1:
55 *AUTHORS=38;5;220;1:*HISTORY=38;5;220;1:*CONTRIBUTORS=38;5;220;1:
56 *PATENTS=38;5;220;1:*VERSION=38;5;220;1:*NOTICE=38;5;220;1:*CHANGES=38;5;220;1:
57 *.log=38;5;190:*Makefile=38;5;155:*MANIFEST=38;5;243:*pm_to_blib=38;5;240:
58 *.txt=38;5;253:*.etx=38;5;184:*.info=38;5;184:*.markdown=38;5;184:*.md=38;5;184:
59 *.mkd=38;5;184:*.nfo=38;5;184:*.pod=38;5;184:*.tex=38;5;184:*.textile=38;5;184:
60 *.json=38;5;178:*.msg=38;5;178:*.pgn=38;5;178:*.rss=38;5;178:*.xml=38;5;178:
61 *.yml=38;5;178:*.RData=38;5;178:*.rdata=38;5;178:*.csv=38;5;78:*.cbr=38;5;141:
62 *.cbz=38;5;141:*.chm=38;5;141:*.djvu=38;5;141:*.pdf=38;5;141:*.PDF=38;5;141:
63 *.docm=38;5;111;4:*.doc=38;5;111:*.docx=38;5;111:*.eps=38;5;111:*.ps=38;5;111:
64 *.odb=38;5;111:*.odt=38;5;111:*.odp=38;5;166:*.pps=38;5;166:*.ppt=38;5;166:
65 *.ods=38;5;112:*.xla=38;5;76:*.xls=38;5;112:*.xlsx=38;5;112:*.xlsxm=38;5;112;4:
66 *.xltm=38;5;73;4:*.xltx=38;5;73:*cfg=38;5;204:*conf=38;5;204:*rc=38;5;204:
67 *.ini=38;5;204:*.gws=38;5;204:*.viminfo=38;5;204:*.pcf=38;5;204:*.psf=38;5;204:
68 *.reg=38;5;203:*.git=38;5;197:*.gitignore=38;5;240:*.gitattributes=38;5;240:
69 *.gitmodules=38;5;240:*.awk=38;5;172:*.bash=38;5;172:*.bat=38;5;172:
70 *.BAT=38;5;172:*.sed=38;5;172:*.sh=38;5;138:*.zsh=38;5;137:*.vim=38;5;254;1:
71 *.ahk=38;5;41:*.py=38;5;41:*.pl=38;5;208:*.PL=38;5;160:*.t=38;5;114:
72 *.msql=38;5;222:*.mysql=38;5;222:*.pgsql=38;5;222:*.sql=38;5;222:
73 *.tcl=38;5;64;1:*.r=38;5;49:*.R=38;5;49:*.gs=38;5;81:*.asm=38;5;81:
74 *.cl=38;5;81:*.lisp=38;5;81:*.lua=38;5;81:*.moon=38;5;81:*.c=38;5;81:
75 *.C=38;5;81:*.h=38;5;110:*.H=38;5;110:*.tcc=38;5;110:*.c++=38;5;81:
76 *.h++=38;5;110:*.hpp=38;5;110:*.hxx=38;5;110:*.ii=38;5;110:*.M=38;5;110:
77 *.m=38;5;110:*.cc=38;5;81:*.cs=38;5;81:*.cp=38;5;81:*.cpp=38;5;81:*.cxx=38;5;81:
78 *.cr=38;5;81:*.go=38;5;81:*.f=38;5;81:*.for=38;5;81:*.ftn=38;5;81:*.s=38;5;110:
79 *.S=38;5;110:*.rs=38;5;81:*.sx=38;5;81:*.hi=38;5;110:*.hs=38;5;81:*.lhs=38;5;81:
80 *.pyc=38;5;240:*.css=38;5;125;1:*.less=38;5;125;1:*.sass=38;5;125;1:
81 *.scss=38;5;125;1:*.htm=38;5;125;1:*.html=38;5;125;1:*.jhtm=38;5;125;1:
82 *.mht=38;5;125;1:*.eml=38;5;125;1:*.mustache=38;5;125;1:*.coffee=38;5;074;1:
83 *.java=38;5;074;1:*.js=38;5;074;1:*.jsm=38;5;074;1:*.jsm=38;5;074;1:
84 *.jsp=38;5;074;1:*.php=38;5;81:*.ctp=38;5;81:*.twig=38;5;81:*.vb=38;5;81:
85 *.vba=38;5;81:*.vbs=38;5;81:*.am=38;5;242:*.in=38;5;242:*.hin=38;5;242:
86 *.scan=38;5;242:*.m4=38;5;242:*.old=38;5;242:*.out=38;5;242:*.SKIP=38;5;244:
87 *.diff=48;5;197;38;5;232:*.patch=48;5;197;38;5;232;1:*.bmp=38;5;129:
88 *.tiff=38;5;97:*.TIFF=38;5;97:*.cdr=38;5;97:*.gif=38;5;97:*.ico=38;5;132:
89 *.jpeg=38;5;125:*.JPG=38;5;125:*.jpg=38;5;125:*.nth=38;5;97:*.png=38;5;197:
90 *.svg=38;5;97:*.xpm=38;5;97:*.avi=38;5;114:*.divx=38;5;114:*.IFO=38;5;114:
91 *.m2v=38;5;114:*.m4v=38;5;114:*.mkv=38;5;114:*.MOV=38;5;114:*.mov=38;5;114:
92 *.mp4=38;5;114:*.mpeg=38;5;114:*.mpg=38;5;114:*.ogm=38;5;114:*.rmvb=38;5;114:
93 *.sample=38;5;114:*.wmv=38;5;114:*.3g2=38;5;115:*.3gp=38;5;115:*.gp3=38;5;115:
94 *.webm=38;5;115:*.gp4=38;5;115:*.asf=38;5;115:*.flv=38;5;115:*.ts=38;5;115:
95 *.ogv=38;5;115:*.f4v=38;5;115:*.VOB=38;5;115;1:*.vob=38;5;115;1:
96 *.3ga=38;5;137;1:*.S3M=38;5;137;1:*.aac=38;5;137;1:*.dat=38;5;137;1:
97 *.dts=38;5;137;1:*.fcm=38;5;137;1:*.m4a=38;5;137;1:*.mid=38;5;137;1:
98 *.midi=38;5;137;1:*.mod=38;5;137;1:*.mp3=38;5;137;1:*.oga=38;5;137;1:
99 *.ogg=38;5;137;1:*.s3m=38;5;137;1:*.sid=38;5;137;1:*.ape=38;5;136;1:
100 *.flac=38;5;136;1:*.alac=38;5;136;1:*.wav=38;5;136;1:*.wv=38;5;136;1:
101 *.wvc=38;5;136;1:*.afm=38;5;66:*.pfb=38;5;66:*.pfm=38;5;66:*.ttf=38;5;66:
102 *.otf=38;5;66:*.PFA=38;5;66:*.pfa=38;5;66:*.7z=38;5;40:*.a=38;5;40:
103 *.arj=38;5;40:*.bz2=38;5;40:*.gz=38;5;40:*.rar=38;5;40:*.tar=38;5;40:
104 *.tgz=38;5;40:*.xz=38;5;40:*.zip=38;5;40:*.r00=38;5;239:*.r01=38;5;239:
105 *.r02=38;5;239:*.r03=38;5;239:*.r04=38;5;239:*.r05=38;5;239:*.r06=38;5;239:
106 *.r07=38;5;239:*.r08=38;5;239:*.r09=38;5;239:*.r10=38;5;239:*.r100=38;5;239:
107 *.r101=38;5;239:*.r102=38;5;239:*.r103=38;5;239:*.r104=38;5;239:
108 *.r105=38;5;239:*.r106=38;5;239:*.r107=38;5;239:*.r108=38;5;239:
109 *.r109=38;5;239:*.r11=38;5;239:*.r110=38;5;239:*.r111=38;5;239:*.r112=38;5;239:
110 *.r113=38;5;239:*.r114=38;5;239:*.r115=38;5;239:*.r116=38;5;239:*.r12=38;5;239:
111 *.r13=38;5;239:*.r14=38;5;239:*.r15=38;5;239:*.r16=38;5;239:*.r17=38;5;239:
112 *.r18=38;5;239:*.r19=38;5;239:*.r20=38;5;239:*.r21=38;5;239:*.r22=38;5;239:
113 *.r25=38;5;239:*.r26=38;5;239:*.r27=38;5;239:*.r28=38;5;239:*.r29=38;5;239:
114 *.r30=38;5;239:*.r31=38;5;239:*.r32=38;5;239:*.r33=38;5;239:*.r34=38;5;239:
115 *.r35=38;5;239:*.r36=38;5;239:*.r37=38;5;239:*.r38=38;5;239:*.r39=38;5;239:
116 *.r40=38;5;239:*.r41=38;5;239:*.r42=38;5;239:*.r43=38;5;239:*.r44=38;5;239:
117 *.r45=38;5;239:*.r46=38;5;239:*.r47=38;5;239:*.r48=38;5;239:*.r49=38;5;239:
118 *.r50=38;5;239:*.r51=38;5;239:*.r52=38;5;239:*.r53=38;5;239:*.r54=38;5;239:
119 *.r55=38;5;239:*.r56=38;5;239:*.r57=38;5;239:*.r58=38;5;239:*.r59=38;5;239:
120 *.r60=38;5;239:*.r61=38;5;239:*.r62=38;5;239:*.r63=38;5;239:*.r64=38;5;239:
121 *.r65=38;5;239:*.r66=38;5;239:*.r67=38;5;239:*.r68=38;5;239:*.r69=38;5;239:
122 *.r69=38;5;239:*.r70=38;5;239:*.r71=38;5;239:*.r72=38;5;239:*.r73=38;5;239:
123 *.r74=38;5;239:*.r75=38;5;239:*.r76=38;5;239:*.r77=38;5;239:*.r78=38;5;239:
124 *.r79=38;5;239:*.r80=38;5;239:*.r81=38;5;239:*.r82=38;5;239:*.r83=38;5;239:
125 *.r84=38;5;239:*.r85=38;5;239:*.r86=38;5;239:*.r87=38;5;239:*.r88=38;5;239:
126 *.r89=38;5;239:*.r90=38;5;239:*.r91=38;5;239:*.r92=38;5;239:*.r93=38;5;239:
127 *.r94=38;5;239:*.r95=38;5;239:*.r96=38;5;239:*.r97=38;5;239:*.r98=38;5;239:
128 *.r99=38;5;239:*.apk=38;5;215:*.deb=38;5;215:*.jad=38;5;215:*.jar=38;5;215:
129 *.cab=38;5;215:*.pak=38;5;215:*.pk3=38;5;215:*.vdf=38;5;215:*.vpk=38;5;215:
130 *.bsp=38;5;215:*.dmg=38;5;215:*.iso=38;5;124:*.bin=38;5;124:*.nrg=38;5;124:
131 *.qcow=38;5;124:*.sparseimage=38;5;124:*.accdb=38;5;60:*.accde=38;5;60:
132 *.accdr=38;5;60:*.accdt=38;5;60:*.db=38;5;60:*.localstorage=38;5;60:
133 *.sqlite=38;5;60:*.typelib=38;5;60:*.nc=38;5;60:*.part=38;5;239:*~=38;5;241:
134 *.pacnew=38;5;33:*.un~=38;5;241:*.orig=38;5;241:*.BUP=38;5;241:*.bak=38;5;241:
135 *.o=38;5;241:*.rlib=38;5;241:*.swp=38;5;244:*.swo=38;5;244:*.tmp=38;5;244:
136 *.sassc=38;5;244:*.pid=38;5;248:*.state=38;5;248:*lockfile=38;5;248:
137 *.err=38;5;160;1:*.error=38;5;160;1:*.stderr=38;5;160;1:*.dump=38;5;241:
138 *.stackdump=38;5;241:*.zcompdump=38;5;241:*.zwc=38;5;241:*.pcap=38;5;29:
139 *.cap=38;5;29:*.dmp=38;5;29:*.allow=38;5;112:*.deny=38;5;196:
140 *.service=38;5;45:*@.service=38;5;45:*.socket=38;5;45:*.swap=38;5;45:
141 *.device=38;5;45:*.mount=38;5;45:*.automount=38;5;45:*.target=38;5;45:
142 *.path=38;5;45:*.timer=38;5;45:*.snapshot=38;5;45:*.application=38;5;116:
143 *.cue=38;5;116:*.description=38;5;116:*.directory=38;5;116:*.m3u=38;5;116:
144 *.m3u8=38;5;116:*.md5=38;5;116:*.properties=38;5;116:*.sfv=38;5;116:
145 *.srt=38;5;116:*.theme=38;5;116:*.torrent=38;5;116:*.urlview=38;5;116:
146 *.asc=38;5;192;3:*.enc=38;5;192;3:*.gpg=38;5;192;3:*.signature=38;5;192;3:
147 *.sig=38;5;192;3:*.p12=38;5;192;3:*.pem=38;5;192;3:*.pgp=38;5;192;3:
148 *.asc=38;5;192;3:*.enc=38;5;192;3:*.sig=38;5;192;3:*.signature=38;5;192;3:
149 *.32x=38;5;213:*.cdi=38;5;213:*.fm2=38;5;213:*.rom=38;5;213:*.sav=38;5;213:
150 *.st=38;5;213:*.a00=38;5;213:*.a52=38;5;213:*.A64=38;5;213:*.a64=38;5;213:
151 *.a78=38;5;213:*.adf=38;5;213:*.atr=38;5;213:*.gb=38;5;213:*.gba=38;5;213:
152 *.gbc=38;5;213:*.gel=38;5;213:*.gg=38;5;213:*.ggl=38;5;213:*.ipk=38;5;213:
153 *.j64=38;5;213:*.nds=38;5;213:*.nes=38;5;213:*.sms=38;5;213:*.pot=38;5;7:
154 *.pcb=38;5;7:*.mm=38;5;7:*.gbr=38;5;7:*.spl=38;5;7:*.scm=38;5;7:
155 *.Rproj=38;5;11:*.sis=38;5;7:*.1p=38;5;7:*.3p=38;5;7:*.cnc=38;5;7:
156 *.def=38;5;7:*.ex=38;5;7:*.example=38;5;7:*.feature=38;5;7:*.ger=38;5;7:
157 *.map=38;5;7:*.mf=38;5;7:*.mfasl=38;5;7:*.mi=38;5;7:*.mtx=38;5;7:*.pc=38;5;7:
158 *.pi=38;5;7:*.plt=38;5;7:*.pm=38;5;7:*.rb=38;5;7:*.rdf=38;5;7:*.rst=38;5;7:
159 *.ru=38;5;7:*.sch=38;5;7:*.sty=38;5;7:*.sug=38;5;7:*.tdy=38;5;7:*.tfm=38;5;7:
160 *.tfnt=38;5;7:*.tg=38;5;7:*.vcard=38;5;7:*.vcf=38;5;7:*.xln=38;5;7';
161 #>
162  
163  
164 $internal_ls_color =~ s/\n//g;
165  
166 # For situations like *.pl=38;5;196;1 (bold and red)
167 my %attributes = (
168 1 => 'bold',
169 2 => 'faint',
170 3 => 'italic',
171 4 => 'underline',
172 5 => 'blink',
173 6 => 'blink_ms',
174 7 => 'reverse',
175 );
176  
177 # Alright, use our own LS_COLORS definition
178 sub ls_color_internal {
179 0 ▶ $LS_COLORS = $internal_ls_color;
Subroutine ls_color_internal: not called CC=1 SCAR=6.9
180 0 $extracted_ls_colors = parse_ls_colors($LS_COLORS);
181 0 ls_color(@_);
182 }
183  
184 sub ls_color_custom {
185 0 ▶ $LS_COLORS = shift;
Subroutine ls_color_custom: not called CC=1 SCAR=6.9
186 0 $extracted_ls_colors = parse_ls_colors($LS_COLORS);
187 0 ls_color(@_);
188 }
189  
190 # Those are the default LS_COLORS mappings from GNU ls
191 sub ls_color_default {
192 0 ▶$LS_COLORS= '
Subroutine ls_color_default: not called CC=1 SCAR=6.9
193 rs=0:di=01;34:ln=01;36:mh=00:pi=40;33:so=01;35:do=01;35:bd=40;33;01:
194 cd=40;33;01:or=40;31;01:mi=00:su=37;41:sg=30;43:ca=30;41:tw=30;42:
195 ow=34;42:st=37;44:ex=01;32:*.tar=01;31:*.tgz=01;31:*.arc=01;31:*.arj=01;31:
196 *.taz=01;31:*.lha=01;31:*.lz4=01;31:*.lzh=01;31:*.lzma=01;31:*.tlz=01;31:
197 *.txz=01;31:*.tzo=01;31:*.t7z=01;31:*.zip=01;31:*.z=01;31:*.dz=01;31:
198 *.gz=01;31:*.lrz=01;31:*.lz=01;31:*.lzo=01;31:*.xz=01;31:*.zst=01;31:
199 *.tzst=01;31:*.bz2=01;31:*.bz=01;31:*.tbz=01;31:*.tbz2=01;31:*.tz=01;31:
200 *.deb=01;31:*.rpm=01;31:*.jar=01;31:*.war=01;31:*.ear=01;31:*.sar=01;31:
201 *.rar=01;31:*.alz=01;31:*.ace=01;31:*.zoo=01;31:*.cpio=01;31:*.7z=01;31:
202 *.rz=01;31:*.cab=01;31:*.wim=01;31:*.swm=01;31:*.dwm=01;31:*.esd=01;31:
203 *.jpg=01;35:*.jpeg=01;35:*.mjpg=01;35:*.mjpeg=01;35:*.gif=01;35:*.bmp=01;35
204 :*.pbm=01;35:*.pgm=01;35:*.ppm=01;35:*.tga=01;35:*.xbm=01;35:*.xpm=01;35:
205 *.tif=01;35:*.tiff=01;35:*.png=01;35:*.svg=01;35:*.svgz=01;35:*.mng=01;35:
206 *.pcx=01;35:*.mov=01;35:*.mpg=01;35:*.mpeg=01;35:*.m2v=01;35:*.mkv=01;35:
207 *.webm=01;35:*.ogm=01;35:*.mp4=01;35:*.m4v=01;35:*.mp4v=01;35:*.vob=01;35:
208 *.qt=01;35:*.nuv=01;35:*.wmv=01;35:*.asf=01;35:*.rm=01;35:*.rmvb=01;35:
209 *.flc=01;35:*.avi=01;35:*.fli=01;35:*.flv=01;35:*.gl=01;35:*.dl=01;35:
210 *.xcf=01;35:*.xwd=01;35:*.yuv=01;35:*.cgm=01;35:*.emf=01;35:*.ogv=01;35:
211 *.ogx=01;35:*.aac=00;36:*.au=00;36:*.flac=00;36:*.m4a=00;36:*.mid=00;36:
212 *.midi=00;36:*.mka=00;36:*.mp3=00;36:*.mpc=00;36:*.ogg=00;36:*.ra=00;36:
213 *.wav=00;36:*.oga=00;36:*.opus=00;36:*.spx=00;36:*.xspf=00;36';
214  
215 0 $LS_COLORS =~ s/\n|\s+//g;
216  
217 0 $extracted_ls_colors = parse_ls_colors($LS_COLORS);
218 0 ls_color(@_);
219 }
220  
221  
222 # none of the ls_color_* variations are called, so we use the the
223 # LS_COLORS defined in the environment variable.
224 $extracted_ls_colors = parse_ls_colors($LS_COLORS);
225  
226  
227 sub ls_color {
228 0 ▶ my @files;
Subroutine ls_color: not called CC=19 SCAR=59.4
229  
230 0 ▶ if(ref($_[0]) eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $_[0] eq 'ARRAY') { } 0 0 0
231 0 push(@files, @{$_[0]});
232 0 shift @_;
233 }
234 else {
235 0 push(@files, @_);
236 }
237  
238  
239 0 for my $file(@files) {
240 0 chomp $file;
241 0 ▶ next if $file =~ m/^\s+$/;
Branch: 1 branch
BranchTrueFalseTotal
if $file =~ /^\s+$/ 0 0 0
242 # it's important to keep the dot if there is one. If you remove the dot,
243 # directories named bin/ can be miscolored given a key like
244 # *.bin=38;5;220
245  
246 0 my($ext) = $file =~ m/.*([.]+.+)$/;
247  
248 # since we need to stat files, we need a real filename that's not padded with
249 # whitespace.
250  
251 0 my $real_file;
252 0 ▶ if($file =~ m/^\s+(.+)/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($file =~ /^\s+(.+)/) { } 0 0 0
253 0 $real_file = $1;
254 }
255 else {
256 0 $real_file = $file;
257 }
258  
259  
260 # no extension found. let's check file attributes. this will only
261 # work if called with absolute paths or from ./ since we can't stat files that
262 # we can't access.
263 # https://github.com/trapd00r/File-LsColor/issues/1
264  
265 # ./recup_dir.5/
266 0 ▶ -d $real_file and $ext = 'di';
Branch: 1 branch
BranchTrueFalseTotal
-d $real_file and $ext = "di" 0 0 0
267  
268 0 ▶ if(!defined($ext)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $ext) 0 0 0
269 0 ▶ -l $real_file and $ext = 'ln'; # symlink
Branch: 1 branch
BranchTrueFalseTotal
-l $real_file and $ext = "ln" 0 0 0
270 0 ▶ -x $real_file and $ext = 'ex'; # executable
Branch: 1 branch
BranchTrueFalseTotal
-x $real_file and $ext = "ex" 0 0 0
271 0 ▶ -d $real_file and $ext = 'di'; # beware, dirs have +x
Branch: 1 branch
BranchTrueFalseTotal
-d $real_file and $ext = "di" 0 0 0
272 0 ▶ -S $real_file and $ext = 'so'; # socket
Branch: 1 branch
BranchTrueFalseTotal
-S $real_file and $ext = "so" 0 0 0
273 0 ▶ -p $real_file and $ext = 'pi'; # fifo, pipe
Branch: 1 branch
BranchTrueFalseTotal
-p $real_file and $ext = "pi" 0 0 0
274 0 ▶ -b $real_file and $ext = 'bd'; # block device
Branch: 1 branch
BranchTrueFalseTotal
-b $real_file and $ext = "bd" 0 0 0
275 0 ▶ -c $real_file and $ext = 'ca'; # character special file
Branch: 1 branch
BranchTrueFalseTotal
-c $real_file and $ext = "ca" 0 0 0
276  
277 # special case for directories that we can't stat, but we can still safely
278 # assume that they are in fact dirs.
279  
280 0 ▶ $real_file =~ m{/$} and $ext = 'di';
Branch: 1 branch
BranchTrueFalseTotal
$real_file =~ m[/$] and $ext = "di" 0 0 0
281 }
282  
283 0 ▶ if(!defined($ext)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $ext) 0 0 0
284 # Since these:
285 # Makefile
286 # README
287 # *Makefile.PL
288 # are all perfectly valid keys
289 0 $ext = $real_file;
290 }
291  
292 0 ▶ if(exists($extracted_ls_colors->{$real_file})) {
Branch: 2 branches
BranchTrueFalseTotal
if (exists $extracted_ls_colors->{$real_file}) { } 0 0 0
elsif (exists $extracted_ls_colors->{$ext}) { } 0 0 0
293 0 $file = fg($extracted_ls_colors->{$real_file}, $file);
294 }
295 elsif(exists($extracted_ls_colors->{$ext})) {
296 0 $file = fg($extracted_ls_colors->{$ext}, $file);
297 }
298 else {
299 # $file = fg(32, $file);
300 }
301 }
302 0 ▶ return wantarray() ? @files : join('', @files);
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
303 }
304  
305  
306 sub get_ls_colors {
307 0 ▶ return parse_ls_colors()
Subroutine get_ls_colors: not called CC=1 SCAR=6.9
308 }
309  
310  
311 sub parse_ls_colors {
312 3 ▶ if(@_) {
Subroutine parse_ls_colors: called CC=5 SCAR=23.1
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 3 0 3
313 3 $LS_COLORS = shift @_;
314 }
315  
316 3 ▶ if( (!defined($LS_COLORS)) or ($LS_COLORS eq '') ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $LS_COLORS or $LS_COLORS eq "") 3 0 3
Condition33%1/3
not defined $LS_COLORS or $LS_COLORS eq ""
l!l&&r!l&&!r
300
MC/DC0%0/2
not defined $LS_COLORS or $LS_COLORS eq ""
not defined $LS_COLORS $LS_COLORS eq ""
Truth table33%1/3
not(A) or B
A= not defined $LS_COLORSB= $LS_COLORS eq ""
ABresult
1X1
011
000
317 3 croak("LS_COLORS variable not set! Nothing to do...\n");
318 }
319 # *.flac=38;5;196
320 0 my @entities = split(/:/, $LS_COLORS);
321  
322 0 my %ft;
323 0 for my $ent(@entities) {
324 # account for:
325 # *.flac - but keep the dot in the extension
326 # *MANIFEST
327 0 my ($filetype, $attributes) = $ent =~ m/[*]*(.?\S+)=([\d;]+|target)/;
328 # print "extracted ft: $filetype | attr: $attributes\n";
329 0 $ft{$filetype} = $attributes;
330 }
331  
332 # if symlink value is target, we use the target key's value
333 # if($ft{ln} eq 'target') {
334 # $ft{ln} = $ft{target};
335 # }
336  
337 # account for:
338 # *.flac
339 # *MANIFEST
340 0 return \%ft;
341 }
342  
343 sub can_ls_color {
344 0 ▶ my $ft = shift;
Subroutine can_ls_color: not called CC=4 SCAR=25.6
345 0 my $table = get_ls_colors();
346  
347 0 $ft =~ s/^\s+//;
348  
349  
350 # if called with an extension that exists, return it.
351 0 ▶ return $table->{$ft} if $table->{$ft};
Branch: 1 branch
BranchTrueFalseTotal
if $table->{$ft} 0 0 0
352 0 ▶ return $table->{".$ft"} if $table->{".$ft"};
Branch: 1 branch
BranchTrueFalseTotal
if $$table{".$ft"} 0 0 0
353  
354 # else, check if called with a filename.ext
355 # return undef if all else fails
356 {
357 3 ▶ no warnings;
Subroutine BEGIN: called CC=1 SCAR=0.2
358 0 my($ext) = $ft =~ m/^.*\.(.+)$/m;
359 0 ▶ return $table->{$ext} ? $table->{$ext} : undef;
Branch: 1 branch
BranchTrueFalseTotal
$table->{$ext} ? : 0 0 0
360 }
361 }
362  
363  
364 1;
365  
366  
367 __END__
↑ Summary