File Coverage

blib/lib/Locale/Codes/Country/FR.pm
Criterion Covered Total %
statement 34 35 97.1
branch 13 14 92.8
condition 7 11 63.6
subroutine 8 8 100.0
pod 3 3 100.0
total 65 71 91.5


line stmt bran cond sub pod time code
1             package Locale::Codes::Country::FR;
2              
3 5     5   1240584 use warnings;
  5         10  
  5         308  
4 5     5   26 use strict;
  5         7  
  5         179  
5              
6 5     5   14637 use Data::Section::Simple;
  5         4443  
  5         585  
7 5     5   3099 use Locale::Codes::Country;
  5         289249  
  5         1130  
8 5     5   54 use Scalar::Util;
  5         9  
  5         2836  
9              
10             our @ISA = ('Locale::Codes::Country');
11              
12             =head1 NAME
13              
14             Locale::Codes::Country::FR - French countries
15              
16             =head1 VERSION
17              
18             Version 0.02
19              
20             =cut
21              
22             our $VERSION = '0.02';
23              
24             =head1 SYNOPSIS
25              
26             DO NOT USE YET - THIS IS STILL P.O.C. code.
27              
28             C is a Perl module that extends L by adding French translations of country names and determining their grammatical gender based on naming conventions.
29             It provides an easy-to-use interface for converting English country names into French and classifying them as masculine or feminine.
30             The module supports both object-oriented and procedural usage.
31             This module will be useful for applications requiring localized country names and gender classification in French.
32              
33             =head1 SUBROUTINES/METHODS
34              
35             =head2 new
36              
37             Creates a Locale::Codes::Country::FR object.
38              
39             =cut
40              
41             sub new {
42 8     8 1 505864 my $class = shift;
43              
44 8 100       42 if(!defined($class)) {
    100          
45             # FIXME: this only works when no arguments are given
46 1         7 $class = __PACKAGE__;
47             } elsif(Scalar::Util::blessed($class)) {
48             # If $class is an object, clone it with new arguments
49 1         4 return bless { %{$class} }, ref($class);
  1         13  
50             }
51              
52             # Return the blessed object
53 7         49 return bless { }, $class;
54             }
55              
56             =head2 en_country2gender
57              
58             Take a country (in English) and return 'M' and 'F'.
59             Can be used in OO or procedural mode.
60              
61             =cut
62              
63             sub en_country2gender
64             {
65 10     10 1 32 my ($self, $country) = @_;
66              
67             # Ensure we are working within the object context
68 10 100 66     59 unless(ref $self && (ref($self) eq __PACKAGE__)) {
69 1         6 return __PACKAGE__->new->en_country2gender($self);
70             }
71              
72             # Translate country to French equivalent
73 9         23 $country = $self->country2fr($country);
74              
75 9 100       29 return if(!defined($country));
76              
77             # Masculine countries that and with an 'e'
78 8 50 33     35 if(($country eq 'Mexique') || ($country eq 'Mozambique')) {
79 0         0 return 'M';
80             }
81              
82             # Determine gender based on French spelling convention
83 8 100       76 return $country =~ /e$/i ? 'F' : 'M';
84             }
85              
86             =head2 country2fr
87              
88             Given a country in English, translate into French.
89             Can be used in OO or procedural mode.
90              
91             =cut
92              
93             sub country2fr {
94 17     17 1 269830 my ($self, $english) = @_;
95              
96             # Ensure we are working within the object context
97 17 100 66     80 unless(ref $self && (ref($self) eq __PACKAGE__)) {
98 1         17 return __PACKAGE__->new->country2fr($self);
99             }
100              
101             # Load the country data section once
102 16   100     75 $self->{country_map} ||= { map { split /:/ } split /\n/, Data::Section::Simple::get_data_section('countries') };
  56         1528  
103              
104 16         105 return $self->{country_map}{$english};
105             }
106              
107             =head1 AUTHOR
108              
109             Nigel Horne, C<< >>
110              
111             =head1 BUGS
112              
113             Please report any bugs or feature requests to the author.
114             This module is provided as-is without any warranty.
115              
116             Lots of countries to be done.
117             This initial release is a POC.
118             While it covers a basic set of country names,
119             future improvements may include handling gender exceptions and expanding the dataset.
120              
121             Gender exceptions aren't handled fully.
122              
123             Please report any bugs or feature requests to C,
124             or through the web interface at
125             L.
126             I will be notified, and then you'll
127             automatically be notified of progress on your bug as I make changes.
128              
129             params() returns a ref which means that calling routines can change the hash
130             for other routines.
131             Take a local copy before making amendments to the table if you don't want unexpected
132             things to happen.
133              
134             =head1 SEE ALSO
135              
136             L
137              
138             =head1 SUPPORT
139              
140             You can find documentation for this module with the perldoc command.
141              
142             perldoc Locale::Codes::Country::FR
143              
144             You can also look for information at:
145              
146             =over 4
147              
148             =item * RT: CPAN's request tracker
149              
150             L
151              
152             =item * Search CPAN
153              
154             L
155              
156             =back
157              
158             =head1 LICENSE AND COPYRIGHT
159              
160             Copyright 2019-2025 Nigel Horne.
161              
162             This program is released under the following licence: GPL2
163              
164             =cut
165              
166             1;
167             __DATA__