| 1 | package Icon::Theme::List; | ||||||||||
| 2 | |||||||||||
| 3 | 2 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 2 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | |||||||||||
| 6 | =head1 NAME | ||||||||||
| 7 | |||||||||||
| 8 | Icon::Theme::List - Lists installed icon themes. | ||||||||||
| 9 | |||||||||||
| 10 | =head1 VERSION | ||||||||||
| 11 | |||||||||||
| 12 | Version 0.0.0 | ||||||||||
| 13 | |||||||||||
| 14 | =cut | ||||||||||
| 15 | |||||||||||
| 16 | 2 | our $VERSION = '0.0.0'; | |||||||||
| 17 | |||||||||||
| 18 | |||||||||||
| 19 | =head1 SYNOPSIS | ||||||||||
| 20 | |||||||||||
| 21 | use Icon::Theme::List; | ||||||||||
| 22 | |||||||||||
| 23 | my $iconlist = Icon::Theme::List->new(); | ||||||||||
| 24 | |||||||||||
| 25 | =head1 FUNCTIONS | ||||||||||
| 26 | |||||||||||
| 27 | =head2 new | ||||||||||
| 28 | |||||||||||
| 29 | This initiates it. | ||||||||||
| 30 | |||||||||||
| 31 | One object is accepted and it is a hash reference. | ||||||||||
| 32 | |||||||||||
| 33 | =head3 args hash | ||||||||||
| 34 | |||||||||||
| 35 | =head4 dir | ||||||||||
| 36 | |||||||||||
| 37 | This dir to use instead of trying to find it automatically. | ||||||||||
| 38 | |||||||||||
| 39 | If this is not specified, the locations below will be checked. | ||||||||||
| 40 | |||||||||||
| 41 | /usr/local/share/icons/ | ||||||||||
| 42 | /usr/share/icons/ | ||||||||||
| 43 | |||||||||||
| 44 | =cut | ||||||||||
| 45 | |||||||||||
| 46 | 0 | ▶ | sub new{ | ||||||||
|
Subroutine
new: not called CC=7 SCAR=40.3
Pod
documented
| |||||||||||
| 47 | 0 | my %args; | |||||||||
| 48 | 0 | ▶ | if(defined($_[1])){ | ||||||||
|
Branch: 1 branch
| |||||||||||
| 49 | 0 | %args= %{$_[1]}; | |||||||||
| 50 | } | ||||||||||
| 51 | 0 | my $function='new'; | |||||||||
| 52 | |||||||||||
| 53 | #create the object | ||||||||||
| 54 | 0 | my $self={error=>undef, errorString=>'', module=>'Icon-Theme-List', perror=>undef}; | |||||||||
| 55 | 0 | bless $self; | |||||||||
| 56 | |||||||||||
| 57 | #if it is not specified check if the two common locations exists | ||||||||||
| 58 | 0 | ▶ | if (!defined($args{dir})) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 59 | 0 | ▶ | if (-d '/usr/local/share/icons/') { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 60 | 0 | $args{dir}='/usr/local/share/icons/'; | |||||||||
| 61 | }else { | ||||||||||
| 62 | 0 | ▶ | if ( -d '/usr/share/icons/') { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 63 | 0 | $args{dir}='/usr/local/share/icons/'; | |||||||||
| 64 | } | ||||||||||
| 65 | } | ||||||||||
| 66 | } | ||||||||||
| 67 | |||||||||||
| 68 | #makes sure we have one | ||||||||||
| 69 | 0 | ▶ | if (!defined($args{dir})) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 70 | 0 | $self->{error}=1; | |||||||||
| 71 | 0 | $self->{perror}=1; | |||||||||
| 72 | 0 | $self->{errorString}='No icon theme directory specified and one could not be located'; | |||||||||
| 73 | 0 | warn($self->{module}.' '.$function.':'.$self->{error}.': '.$self->{errorString}); | |||||||||
| 74 | 0 | return $self; | |||||||||
| 75 | } | ||||||||||
| 76 | |||||||||||
| 77 | #make sure it is really a directory | ||||||||||
| 78 | 0 | ▶ | if (! -d $args{dir}) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 79 | 0 | $self->{error}=2; | |||||||||
| 80 | 0 | $self->{perror}=1; | |||||||||
| 81 | 0 | $self->{errorString}='"'.$args{dir}.'" is not a directory'; | |||||||||
| 82 | 0 | warn($self->{module}.' '.$function.':'.$self->{error}.': '.$self->{errorString}); | |||||||||
| 83 | 0 | return $self; | |||||||||
| 84 | } | ||||||||||
| 85 | |||||||||||
| 86 | #saves it for later usage | ||||||||||
| 87 | 0 | $self->{dir}=$args{dir}; | |||||||||
| 88 | |||||||||||
| 89 | 0 | return $self; | |||||||||
| 90 | } | ||||||||||
| 91 | |||||||||||
| 92 | =head2 check | ||||||||||
| 93 | |||||||||||
| 94 | This checks if the specified theme is present. | ||||||||||
| 95 | |||||||||||
| 96 | One arguement is required and that is the name of the theme | ||||||||||
| 97 | to check to see if it is present. | ||||||||||
| 98 | |||||||||||
| 99 | A return value of true means it is present. | ||||||||||
| 100 | |||||||||||
| 101 | my $returned=$iconlist->check('hicolor'); | ||||||||||
| 102 | if( $iconlist->{error} ){ | ||||||||||
| 103 | print "Error!\n"; | ||||||||||
| 104 | }else{ | ||||||||||
| 105 | if( $returned ){ | ||||||||||
| 106 | print "It is present.\n"; | ||||||||||
| 107 | } | ||||||||||
| 108 | } | ||||||||||
| 109 | |||||||||||
| 110 | =cut | ||||||||||
| 111 | |||||||||||
| 112 | 0 | ▶ | sub check{ | ||||||||
|
Subroutine
check: not called CC=6 SCAR=37.4
Pod
documented
| |||||||||||
| 113 | 0 | my $self=$_[0]; | |||||||||
| 114 | 0 | my $theme=$_[1]; | |||||||||
| 115 | 0 | my $function='list'; | |||||||||
| 116 | |||||||||||
| 117 | 0 | $self->errorblank; | |||||||||
| 118 | 0 | ▶ | if ($self->{error}) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 119 | 0 | warn($self->{module}.' '.$function.': A permanent error is set'); | |||||||||
| 120 | 0 | return undef; | |||||||||
| 121 | } | ||||||||||
| 122 | |||||||||||
| 123 | #make sure a theme was specified | ||||||||||
| 124 | 0 | ▶ | if (!defined($theme)) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 125 | 0 | $self->{error}=3; | |||||||||
| 126 | 0 | $self->{errorString}='No theme specified'; | |||||||||
| 127 | 0 | warn($self->{module}.' '.$function.':'.$self->{error}.': '.$self->{errorString}); | |||||||||
| 128 | 0 | return undef; | |||||||||
| 129 | } | ||||||||||
| 130 | |||||||||||
| 131 | #gets the list | ||||||||||
| 132 | 0 | my @themes=$self->list; | |||||||||
| 133 | 0 | ▶ | if ($self->{error}) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 134 | 0 | warn($self->{module}.' '.$function.': list errored'); | |||||||||
| 135 | 0 | return undef; | |||||||||
| 136 | } | ||||||||||
| 137 | |||||||||||
| 138 | #checks for a match | ||||||||||
| 139 | 0 | my $int=0; | |||||||||
| 140 | 0 | ▶ | while (defined( $themes[$int] )) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 141 | 0 | ▶ | if ($themes[$int] eq $theme) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 142 | 0 | return 1; | |||||||||
| 143 | } | ||||||||||
| 144 | |||||||||||
| 145 | 0 | $int++; | |||||||||
| 146 | } | ||||||||||
| 147 | |||||||||||
| 148 | 0 | return undef; | |||||||||
| 149 | } | ||||||||||
| 150 | |||||||||||
| 151 | =head2 list | ||||||||||
| 152 | |||||||||||
| 153 | This lists the available icon themes. | ||||||||||
| 154 | |||||||||||
| 155 | The returned value is a array. | ||||||||||
| 156 | |||||||||||
| 157 | my @themes=$iconlist->list; | ||||||||||
| 158 | if($iconlist->{error}){ | ||||||||||
| 159 | print "Error!\n"; | ||||||||||
| 160 | } | ||||||||||
| 161 | |||||||||||
| 162 | =cut | ||||||||||
| 163 | |||||||||||
| 164 | 0 | ▶ | sub list{ | ||||||||
|
Subroutine
list: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||
| 165 | 0 | my $self=$_[0]; | |||||||||
| 166 | 0 | my $function='list'; | |||||||||
| 167 | |||||||||||
| 168 | 0 | $self->errorblank; | |||||||||
| 169 | 0 | ▶ | if ($self->{error}) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 170 | 0 | warn($self->{module}.' '.$function.': A permanent error is set'); | |||||||||
| 171 | 0 | return undef; | |||||||||
| 172 | } | ||||||||||
| 173 | |||||||||||
| 174 | 0 | opendir(LIST, $self->{dir}); | |||||||||
| 175 | 0 | my @themes=grep(!/\./, readdir(LIST) ); | |||||||||
| 176 | 0 | closedir(LIST); | |||||||||
| 177 | |||||||||||
| 178 | 0 | return @themes; | |||||||||
| 179 | } | ||||||||||
| 180 | |||||||||||
| 181 | =head2 errorblank | ||||||||||
| 182 | |||||||||||
| 183 | This is a internal that blanks any previous errors. | ||||||||||
| 184 | |||||||||||
| 185 | =cut | ||||||||||
| 186 | |||||||||||
| 187 | 0 | ▶ | sub errorblank{ | ||||||||
|
Subroutine
errorblank: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||
| 188 | 0 | my $self=$_[0]; | |||||||||
| 189 | |||||||||||
| 190 | 0 | ▶ | if ($self->{perror}) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 191 | 0 | return undef; | |||||||||
| 192 | } | ||||||||||
| 193 | |||||||||||
| 194 | 0 | $self->{error}=undef; | |||||||||
| 195 | 0 | $self->{errorString}=""; | |||||||||
| 196 | |||||||||||
| 197 | 0 | return 1; | |||||||||
| 198 | }; | ||||||||||
| 199 | |||||||||||
| 200 | |||||||||||
| 201 | =head1 ERROR CODES | ||||||||||
| 202 | |||||||||||
| 203 | The current error code can be found by checking $iconlist->{error}. If it is true, | ||||||||||
| 204 | a error is present. A more verbose description can be found by checking | ||||||||||
| 205 | $iconlist->{errorString}. | ||||||||||
| 206 | |||||||||||
| 207 | If $iconlist->{perror} is true, then it means that a permanent error is set. | ||||||||||
| 208 | |||||||||||
| 209 | =head2 1 | ||||||||||
| 210 | |||||||||||
| 211 | No dir specified and one could not be located. | ||||||||||
| 212 | |||||||||||
| 213 | This means that the locations listed below don't exist. | ||||||||||
| 214 | |||||||||||
| 215 | /usr/local/share/icons/ | ||||||||||
| 216 | /usr/share/icons/ | ||||||||||
| 217 | |||||||||||
| 218 | =head2 2 | ||||||||||
| 219 | |||||||||||
| 220 | The specified icon directory is actually not a directory. | ||||||||||
| 221 | |||||||||||
| 222 | =head2 3 | ||||||||||
| 223 | |||||||||||
| 224 | No theme specified. | ||||||||||
| 225 | |||||||||||
| 226 | =head1 AUTHOR | ||||||||||
| 227 | |||||||||||
| 228 | Zane C. Bowers, C<< <vvelox at vvelox.net> >> | ||||||||||
| 229 | |||||||||||
| 230 | =head1 BUGS | ||||||||||
| 231 | |||||||||||
| 232 | Please report any bugs or feature requests to C<bug-icon-theme-list at rt.cpan.org>, or through | ||||||||||
| 233 | the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Icon-Theme-List>. I will be notified, and then you'll | ||||||||||
| 234 | automatically be notified of progress on your bug as I make changes. | ||||||||||
| 235 | |||||||||||
| 236 | |||||||||||
| 237 | |||||||||||
| 238 | |||||||||||
| 239 | =head1 SUPPORT | ||||||||||
| 240 | |||||||||||
| 241 | You can find documentation for this module with the perldoc command. | ||||||||||
| 242 | |||||||||||
| 243 | perldoc Icon::Theme::List | ||||||||||
| 244 | |||||||||||
| 245 | |||||||||||
| 246 | You can also look for information at: | ||||||||||
| 247 | |||||||||||
| 248 | =over 4 | ||||||||||
| 249 | |||||||||||
| 250 | =item * RT: CPAN's request tracker | ||||||||||
| 251 | |||||||||||
| 252 | L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Icon-Theme-List> | ||||||||||
| 253 | |||||||||||
| 254 | =item * AnnoCPAN: Annotated CPAN documentation | ||||||||||
| 255 | |||||||||||
| 256 | L<http://annocpan.org/dist/Icon-Theme-List> | ||||||||||
| 257 | |||||||||||
| 258 | =item * CPAN Ratings | ||||||||||
| 259 | |||||||||||
| 260 | L<http://cpanratings.perl.org/d/Icon-Theme-List> | ||||||||||
| 261 | |||||||||||
| 262 | =item * Search CPAN | ||||||||||
| 263 | |||||||||||
| 264 | L<http://search.cpan.org/dist/Icon-Theme-List/> | ||||||||||
| 265 | |||||||||||
| 266 | =back | ||||||||||
| 267 | |||||||||||
| 268 | |||||||||||
| 269 | =head1 ACKNOWLEDGEMENTS | ||||||||||
| 270 | |||||||||||
| 271 | |||||||||||
| 272 | =head1 COPYRIGHT & LICENSE | ||||||||||
| 273 | |||||||||||
| 274 | Copyright 2009 Zane C. Bowers, all rights reserved. | ||||||||||
| 275 | |||||||||||
| 276 | This program is free software; you can redistribute it and/or modify it | ||||||||||
| 277 | under the same terms as Perl itself. | ||||||||||
| 278 | |||||||||||
| 279 | |||||||||||
| 280 | =cut | ||||||||||
| 281 | |||||||||||
| 282 | 2 | 1; # End of Icon::Theme::List | |||||||||