| 1 | package Slackware::Slackget::Local; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 1 | require Slackware::Slackget::File ; | |||||||||||||||||||||||||||
| 7 | 1 | require XML::Simple; | |||||||||||||||||||||||||||
| 8 | 1 | $XML::Simple::PREFERRED_PARSER='XML::Parser' ; | |||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | =head1 NAME | ||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | Slackware::Slackget::Local - A class to load the locales | ||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | =head1 VERSION | ||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | Version 1.0.0 | ||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | =cut | ||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | 1 | our $VERSION = '1.0.0'; | |||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | This class' purpose is to load and export the local. | ||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | use Slackware::Slackget::Local; | ||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | my $local = Slackware::Slackget::Local->new(); | ||||||||||||||||||||||||||||
| 29 | $local->load('/usr/local/share/slack-get/local/french.xml'); | ||||||||||||||||||||||||||||
| 30 | print $local->get('__SETTINGS') ; | ||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | =cut | ||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | sub new | ||||||||||||||||||||||||||||
| 35 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
new: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||
| 36 | 0 | my ($class,$file) = @_ ; | |||||||||||||||||||||||||||
| 37 | 0 | my $self={}; | |||||||||||||||||||||||||||
| 38 | 0 | bless($self,$class); | |||||||||||||||||||||||||||
| 39 | 0 | ▶ | if(defined($file) && -e $file) | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $file and -e $file
MC/DC0%0/2
defined $file and -e $file
defined $file
-e $file
Truth table0%0/3
A and B
A= defined $fileB= -e $file
| |||||||||||||||||||||||||||||
| 40 | { | ||||||||||||||||||||||||||||
| 41 | 0 | $self->Load($file); | |||||||||||||||||||||||||||
| 42 | } | ||||||||||||||||||||||||||||
| 43 | 0 | return $self; | |||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | =head1 CONSTRUCTOR | ||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | =head2 new | ||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | Can take an argument : the LC_MESSAGES file. In this case the constructor automatically call the Load() method. | ||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | my $local = new Slackware::Slackget::Local(); | ||||||||||||||||||||||||||||
| 53 | or | ||||||||||||||||||||||||||||
| 54 | my $local = new Slackware::Slackget::Local('/usr/local/share/slack-get/local/french.xml'); | ||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | =head1 FUNCTIONS | ||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | =head2 Load (deprecated) | ||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | Same as load(), provided for backward compatibility. | ||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | =cut | ||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | 0 | ▶ | sub Load { | ||||||||||||||||||||||||||
|
Subroutine
Load: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 65 | 0 | return load(@_); | |||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | =head2 load | ||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | Load the local from a given file | ||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | $local->load('/usr/local/share/slack-get/local/french.xml') or die "unable to load local\n"; | ||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | Return undef if something goes wrong, 1 else. | ||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||
| 76 | =cut | ||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | 0 | ▶ | sub load { | ||||||||||||||||||||||||||
|
Subroutine
load: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||
| 79 | 0 | my ($self,$file) = @_ ; | |||||||||||||||||||||||||||
| 80 | 0 | ▶ | return undef unless(defined($file) && -e $file); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $file and -e $file
MC/DC0%0/2
defined $file and -e $file
defined $file
-e $file
Truth table0%0/3
A and B
A= defined $fileB= -e $file
| |||||||||||||||||||||||||||||
| 81 | 0 | print "[Slackware::Slackget::Local] loading file \"$file\"\n"; | |||||||||||||||||||||||||||
| 82 | 0 | my $data = XML::Simple::XMLin( $file , KeyAttr=> {'message' => 'id'}) ; | |||||||||||||||||||||||||||
| 83 | 0 | $self->{DATA} = $data->{'message'} ; | |||||||||||||||||||||||||||
| 84 | 0 | $self->{LP_NAME} = $data->{name} ; | |||||||||||||||||||||||||||
| 85 | 0 | return 1; | |||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||
| 88 | =head2 get_indexes | ||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||
| 90 | Return the list of all index of the current loaded local. Dependending of the context, this method return an array or an arrayref. | ||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||
| 92 | # Return a list | ||||||||||||||||||||||||||||
| 93 | foreach ($local->get_indexes) { | ||||||||||||||||||||||||||||
| 94 | print "$_ : ",$local->Get($_),"\n"; | ||||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||
| 97 | # Return an arrayref | ||||||||||||||||||||||||||||
| 98 | my $index_list = $local->get_indexes ; | ||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||
| 100 | =cut | ||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||
| 102 | sub get_indexes | ||||||||||||||||||||||||||||
| 103 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
get_indexes: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 104 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 105 | 0 | my @a = keys( %{$self->{DATA} }); | |||||||||||||||||||||||||||
| 106 | 0 | ▶ | return wantarray ? @a : \@a; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 107 | } | ||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||
| 109 | =head2 Get (deprecated) | ||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||
| 111 | Same as get(), provided for backward compatibility. | ||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||
| 113 | =cut | ||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||
| 115 | 0 | ▶ | sub Get { | ||||||||||||||||||||||||||
|
Subroutine
Get: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 116 | 0 | return get(@_); | |||||||||||||||||||||||||||
| 117 | } | ||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||
| 119 | =head2 get | ||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||
| 121 | Return the localized message of a given token : | ||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||
| 123 | my $error_on_modification = $local->get('__ERR_MOD') ; | ||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||
| 125 | Return undef if the token doesn't exist. | ||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||
| 127 | You can also pass extra arguments to this method, and if their is wildcards in the token they will be replace by those values. Wildcards are %1, %2, ..., %x. | ||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||
| 129 | Here is and example : | ||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||
| 131 | # The token is : | ||||||||||||||||||||||||||||
| 132 | # __NETWORK_CONNECTION_ERROR = Error, cannot connect to %1, the server said ``%2''. | ||||||||||||||||||||||||||||
| 133 | my $localized_token = $local->get('__NETWORK_CONNECTION_ERROR', '192.168.0.42', 'Connection not authorized'); | ||||||||||||||||||||||||||||
| 134 | print "$localized_token\n"; | ||||||||||||||||||||||||||||
| 135 | # $localized_token contains the string "Error, cannot connect to 192.168.0.42, the server said ``Connection not authorized''." | ||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||
| 138 | =cut | ||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||
| 140 | 0 | ▶ | sub get { | ||||||||||||||||||||||||||
|
Subroutine
get: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||
| 141 | 0 | my ($self,$token,@args) = @_ ; | |||||||||||||||||||||||||||
| 142 | 0 | ▶ | if(@args) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 143 | { | ||||||||||||||||||||||||||||
| 144 | 0 | @args = (0,@args); | |||||||||||||||||||||||||||
| 145 | 0 | my $tmp = $self->{DATA}->{$token}->{'content'}; | |||||||||||||||||||||||||||
| 146 | 0 | ▶ | for(my $k=1;$k<=$#args; $k++) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 147 | { | ||||||||||||||||||||||||||||
| 148 | 0 | $tmp =~ s/%$k/$args[$k]/g ; | |||||||||||||||||||||||||||
| 149 | } | ||||||||||||||||||||||||||||
| 150 | 0 | return $tmp; | |||||||||||||||||||||||||||
| 151 | } | ||||||||||||||||||||||||||||
| 152 | else | ||||||||||||||||||||||||||||
| 153 | { | ||||||||||||||||||||||||||||
| 154 | 0 | return $self->{DATA}->{$token}->{'content'}; | |||||||||||||||||||||||||||
| 155 | } | ||||||||||||||||||||||||||||
| 156 | } | ||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||
| 158 | =head2 to_XML (deprecated) | ||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||
| 160 | Same as to_xml(), provided for backward compatibility. | ||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||
| 162 | =cut | ||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||
| 164 | 0 | ▶ | sub to_XML { | ||||||||||||||||||||||||||
|
Subroutine
to_XML: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 165 | 0 | return to_xml(@_); | |||||||||||||||||||||||||||
| 166 | } | ||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||
| 168 | sub to_xml | ||||||||||||||||||||||||||||
| 169 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
to_xml: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||
| 170 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 171 | 0 | my @msg = sort {$a cmp $b} keys(%{ $self->{DATA} }); | |||||||||||||||||||||||||||
| 172 | 0 | my $xml = "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"yes\"?>\n<local name=\"$self->{LP_NAME}\">\n"; | |||||||||||||||||||||||||||
| 173 | 0 | foreach my $token (@msg) | |||||||||||||||||||||||||||
| 174 | { | ||||||||||||||||||||||||||||
| 175 | 0 | ▶ | unless(defined( $self->{DATA}->{$token}->{content} )) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 176 | { | ||||||||||||||||||||||||||||
| 177 | 0 | print "token \"$token\" have no associate value.\n"; | |||||||||||||||||||||||||||
| 178 | 0 | next; | |||||||||||||||||||||||||||
| 179 | } | ||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||
| 181 | 0 | $xml .= "\t<message id=\"$token\"><![CDATA[$self->{DATA}->{$token}->{content}]]></message>\n"; | |||||||||||||||||||||||||||
| 182 | } | ||||||||||||||||||||||||||||
| 183 | 0 | $xml .= "</local>"; | |||||||||||||||||||||||||||
| 184 | } | ||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||
| 186 | =head2 name | ||||||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||||||
| 188 | Accessor for the name of the Local (langpack). | ||||||||||||||||||||||||||||
| 189 | |||||||||||||||||||||||||||||
| 190 | print "The current langpack name is : ", $local->name,"\n"; | ||||||||||||||||||||||||||||
| 191 | $local->name('Japanese'); # Set the name of the langpack to 'Japanese'. | ||||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||
| 193 | =cut | ||||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||
| 195 | sub name | ||||||||||||||||||||||||||||
| 196 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
name: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 197 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 198 | 0 | my $name = shift; | |||||||||||||||||||||||||||
| 199 | 0 | ▶ | return $name ? ($self->{LP_NAME}=$name) : $self->{LP_NAME}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 200 | } | ||||||||||||||||||||||||||||
| 201 | |||||||||||||||||||||||||||||
| 202 | =head1 AUTHOR | ||||||||||||||||||||||||||||
| 203 | |||||||||||||||||||||||||||||
| 204 | DUPUIS Arnaud, C<< <a.dupuis@infinityperl.org> >> | ||||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||
| 206 | =head1 BUGS | ||||||||||||||||||||||||||||
| 207 | |||||||||||||||||||||||||||||
| 208 | Please report any bugs or feature requests to | ||||||||||||||||||||||||||||
| 209 | C<bug-Slackware-Slackget@rt.cpan.org>, or through the web interface at | ||||||||||||||||||||||||||||
| 210 | L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Slackware-Slackget>. | ||||||||||||||||||||||||||||
| 211 | I will be notified, and then you'll automatically be notified of progress on | ||||||||||||||||||||||||||||
| 212 | your bug as I make changes. | ||||||||||||||||||||||||||||
| 213 | |||||||||||||||||||||||||||||
| 214 | =head1 SUPPORT | ||||||||||||||||||||||||||||
| 215 | |||||||||||||||||||||||||||||
| 216 | You can find documentation for this module with the perldoc command. | ||||||||||||||||||||||||||||
| 217 | |||||||||||||||||||||||||||||
| 218 | perldoc Slackware::Slackget::Local | ||||||||||||||||||||||||||||
| 219 | |||||||||||||||||||||||||||||
| 220 | |||||||||||||||||||||||||||||
| 221 | You can also look for information at: | ||||||||||||||||||||||||||||
| 222 | |||||||||||||||||||||||||||||
| 223 | =over 4 | ||||||||||||||||||||||||||||
| 224 | |||||||||||||||||||||||||||||
| 225 | =item * Infinity Perl website | ||||||||||||||||||||||||||||
| 226 | |||||||||||||||||||||||||||||
| 227 | L<http://www.infinityperl.org/category/slack-get> | ||||||||||||||||||||||||||||
| 228 | |||||||||||||||||||||||||||||
| 229 | =item * slack-get specific website | ||||||||||||||||||||||||||||
| 230 | |||||||||||||||||||||||||||||
| 231 | L<http://slackget.infinityperl.org> | ||||||||||||||||||||||||||||
| 232 | |||||||||||||||||||||||||||||
| 233 | =item * RT: CPAN's request tracker | ||||||||||||||||||||||||||||
| 234 | |||||||||||||||||||||||||||||
| 235 | L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Slackware-Slackget> | ||||||||||||||||||||||||||||
| 236 | |||||||||||||||||||||||||||||
| 237 | =item * AnnoCPAN: Annotated CPAN documentation | ||||||||||||||||||||||||||||
| 238 | |||||||||||||||||||||||||||||
| 239 | L<http://annocpan.org/dist/Slackware-Slackget> | ||||||||||||||||||||||||||||
| 240 | |||||||||||||||||||||||||||||
| 241 | =item * CPAN Ratings | ||||||||||||||||||||||||||||
| 242 | |||||||||||||||||||||||||||||
| 243 | L<http://cpanratings.perl.org/d/Slackware-Slackget> | ||||||||||||||||||||||||||||
| 244 | |||||||||||||||||||||||||||||
| 245 | =item * Search CPAN | ||||||||||||||||||||||||||||
| 246 | |||||||||||||||||||||||||||||
| 247 | L<http://search.cpan.org/dist/Slackware-Slackget> | ||||||||||||||||||||||||||||
| 248 | |||||||||||||||||||||||||||||
| 249 | =back | ||||||||||||||||||||||||||||
| 250 | |||||||||||||||||||||||||||||
| 251 | =head1 ACKNOWLEDGEMENTS | ||||||||||||||||||||||||||||
| 252 | |||||||||||||||||||||||||||||
| 253 | Thanks to Bertrand Dupuis (yes my brother) for his contribution to the documentation. | ||||||||||||||||||||||||||||
| 254 | |||||||||||||||||||||||||||||
| 255 | =head1 SEE ALSO | ||||||||||||||||||||||||||||
| 256 | |||||||||||||||||||||||||||||
| 257 | =head1 COPYRIGHT & LICENSE | ||||||||||||||||||||||||||||
| 258 | |||||||||||||||||||||||||||||
| 259 | Copyright 2005 DUPUIS Arnaud, All Rights Reserved. | ||||||||||||||||||||||||||||
| 260 | |||||||||||||||||||||||||||||
| 261 | This program is free software; you can redistribute it and/or modify it | ||||||||||||||||||||||||||||
| 262 | under the same terms as Perl itself. | ||||||||||||||||||||||||||||
| 263 | |||||||||||||||||||||||||||||
| 264 | =cut | ||||||||||||||||||||||||||||
| 265 | |||||||||||||||||||||||||||||
| 266 | 1 | 1; # End of Slackware::Slackget::Local | |||||||||||||||||||||||||||