File Coverage

blib/lib/MojoX/DirectoryListing/Icons.pm
Criterion Covered Total %
statement 24 26 92.3
branch 10 12 83.3
condition 2 3 66.6
subroutine 5 5 100.0
pod 2 2 100.0
total 43 48 89.5


line stmt bran cond sub pod time code
1             package MojoX::DirectoryListing::Icons;
2 6     6   54 use base 'Exporter';
  6         15  
  6         963  
3 6     6   57 use strict;
  6         14  
  6         269  
4 6     6   47 use warnings;
  6         13  
  6         5820  
5              
6             our @EXPORT = qw(choose_icon get_icon);
7             our $VERSION = '0.12';
8             our %BYTES;
9              
10             sub get_icon {
11 5     5 1 294 my $word = shift;
12 5   66     34 return $BYTES{$word} // $BYTES{"unknown"};
13             }
14              
15             sub choose_icon {
16 64     64 1 710 my $item = shift;
17 64         160 my ($name,$type) = ($item->{name}, $item->{type});
18 64 100       136 if ($name eq '..') {
19 10         32 return "back";
20             }
21 54 100       108 if ($item->{is_dir}) {
22 16         42 return "folder";
23             }
24 38 100       76 if ($name eq 'README') {
25 1         5 return "hand-right";
26             }
27 37 50       130 if ($name =~ /Makefile($|\.)/i) {
28 0         0 return "text";
29             }
30             # text file types from App::Ack
31 37 100       273 if ($type =~ /^( ad[abs] | asm | s | bat | cmd | c | h | xs |
32             cf[cm] | cfml | clj | cpp | cc | cxx | m | hpp |
33             hh | hxx | css? | pas | int | dfm | nfm | dof |
34             dpk | dproj | el | erl | hrl | f | f\d\d |
35             for | ftn | fpp | go | groovy | gtmpl | gpp |
36             grunit | hs | lhs | html? | [sx]html | java |
37             properties | js | jspx? | jhtm | jhtml | li?sp |
38             lua | mas | mhtml | mpl | mtxt | mm | mli? |
39             pir | pasm | pmc | ops | pod | pg | tg | pl | pm6? |
40             pod | t | php[t345]? | phtml | c?pt | metadata |
41             cpy | py | Rakefiles | rb | rhtml | rjs | rxml |
42             erb | rake | spec | scala | scm | ss | sh | bash |
43             csh | tcsh | ksh | zsh | st | sql | ctl | i?tcl |
44             itl | tex | cls | sty | te?xt | latex | tt |
45             tt2 | ttml | bas | cls | frm | ctl | vb | resx |
46             v | vh | sv | vhd | vhdl | vim | yaml | yml |
47             xml | dtd | xslt? | ent | json | ini | Changes )$/ix) {
48 27         83 return "text";
49             }
50 10 50       50 if ($type =~ /^( jpe?g | gif | png | tiff? | icon? | xbm | ps )$/ix) {
51 10         31 return "image";
52             }
53 0           return "unknown";
54             }
55              
56             # v0.07: icon identifiers are matched with a :icon placeholder
57             # so the keys in this hash must never contain '/' or '.'
58              
59             our %ICONS = (
60              
61             text => "47494638396114001600C20000FFFFFFCCFFFF99999933333300000000000000000000000021FE4E546869732061727420697320696E20746865207075626C696320646F6D61696E2E204B6576696E204875676865732C206B6576696E68406569742E636F6D2C2053657074656D62657220313939350021F90401000001002C000000001400160000035838BABCF1300C40AB9D23BE693BCF11D75522B88DD7057144EB52C410CF270ABB6E8DB796E00B849AADF20B4A6EBB1705281C128DACA412C03C3A7B50A4F4D9BC5645DAE9F78AED6E975932BAEBFC0E7EF0B84F1691DA8D09003",
62              
63             back => "47494638396114001600C20000FFFFFFCCFFFF99999966666633333300000000000000000021FE4E546869732061727420697320696E20746865207075626C696320646F6D61696E2E204B6576696E204875676865732C206B6576696E68406569742E636F6D2C2053657074656D62657220313939350021F90401000001002C000000001400160000034B18BADCFE2310F26A103353BBA2CEDCF5699C374E16768290740605372A451C6E586D2FFB92EB354650F103EA78C6A491A66C16284EA720DA8CC0A83A824018D55692DED055FCE891CF8B04003B",
64              
65             folder => "47494638396114001600C20000FFFFFFFFCC99CCFFFF99663333333300000000000000000021FE4E546869732061727420697320696E20746865207075626C696320646F6D61696E2E204B6576696E204875676865732C206B6576696E68406569742E636F6D2C2053657074656D62657220313939350021F90401000002002C000000001400160000035428BADCFE30CA4959B9F8CE12BAEF45C47D64A629C5407A6A8906432CC72B1C8EF51A13579E0F3C9C8F05EC0D4945E171673CB2824E2234DA495261569856C5DDC27882D46C3C2680C3E6B47ACD232C4CF08C3B01003B",
66              
67             "hand-right" => "47494638396114001600C20000FFFFFFFFCC99CCFFFF99663300000000000000000000000021FE4E546869732061727420697320696E20746865207075626C696320646F6D61696E2E204B6576696E204875676865732C206B6576696E68406569742E636F6D2C2053657074656D62657220313939350021F90401000002002C000000001400160000034C28BADCFE30CA491DB9B892C03B91572762E4258462306C29B7B6AC38CC74CC11C3589A699C7B8DC0E6F273A956C163B12874085BAAE3A7F1928D1E28EB6C8AED14B911DF5653AA98CF684A02003B",
68              
69             unknown => "47494638396114001600C20000FFFFFFCCFFFF99999933333300000000000000000000000021FE4E546869732061727420697320696E20746865207075626C696320646F6D61696E2E204B6576696E204875676865732C206B6576696E68406569742E636F6D2C2053657074656D62657220313939350021F90401000001002C000000001400160000036838BABCF1300C40AB9D23BE693BCF11070802619A22B851E5798A80CAB52E4A0C37B102AE30D6A79DABD223E9249D0A8D402AED2C4B13EB08FBD57CBF270588CD222DBD8EF34B3C25C7D52494DA198AD960F35BCB93AFE96A253C3F970C9A80812438114086410109003B",
70              
71             image => "47494638396114001600E30000FFFFFFFF3333CCFFFFCCCCCC9999996666666600003333330099CC00993300336600000000000000000000000000000021FE4E546869732061727420697320696E20746865207075626C696320646F6D61696E2E204B6576696E204875676865732C206B6576696E68406569742E636F6D2C2053657074656D62657220313939350021F90401000002002C0000000014001600000490F0C849A7B8581CC0BBDF47766D5E49861959762A3A02412C0703A0DAD836CB06B01CBFE06B17EB2D8EC8C590D8E3109E04A506364B5813350054AA932538036B56CB050C62DFF0953488BE060603F66ADD0C14EE6987BE1E20F0652C7C0507087F7937030757848687811D8A138E8F2F2B6694957A257E9980961E770AA3A49F9B9725880750ACAD4F401949B2B35211003B",
72              
73             );
74              
75             %BYTES = map {
76             my $ico = $ICONS{$_};
77             my $bytes = pack "H*", $ico;
78             $_ => $bytes
79             } keys %ICONS;
80              
81             1;
82              
83             =head1 NAME
84              
85             MojoX::DirectoryListing::Icons - icon data for directory listing in
86             a web application
87              
88             =head1 FUNCTIONS
89              
90             =head2 choose_icon
91              
92             Returns the appropriate icon id (like C or C)
93             for a directory listing item.
94              
95             =head2 get_icon
96              
97             Returns the binary data representing the specified icon.
98              
99             =head1 SEE ALSO
100              
101             L
102              
103             =cut