Hello xeno,
I appreciate your selecting my module and your querying about coercion.
And I'm sorry for my wrong operation on RT (deletion of the ticket).
I received your query:
* "Why the coercions operating on only letter-case?"
* "Why not code to code conversions?"
* "Why not code to name conversions?"
Just then, I will release the succeeding module
"MooseX::Types::Locale::Codes"
(
https://github.com/gardejo/p5-moosex-types-locale-codes/ ), until
"MooseX::Types::Parameterizable" solves an issue about coercion
(
https://github.com/jjn1056/MooseX-Types-Parameterizable/issues/5 ).
So, I notify the reasons of the behaviors and my future plans to you.
Case 1. some code set to other code set
---------------------------------------
* concrete example: CountryCode->check('GB')
* current result: true
* coming result: true
* concrete example: CountryCode->check('UK')
* current result: false
* coming result: false
* concrete example: CountryCode->coerce('UK')
* current result: 'UK'
* coming result: 'UK' (not 'GB')
For a technical reason, I'm taking the liberty to omission of the coercion.
See "case1_code_to_code.t".
Case 2. name to code
--------------------
* concrete example: CountryCode->coerce('United States')
* current result: 'UNITED STATES'
* coming result: 'US'
I have a good idea about what you mean.
I will do it on the succeeding module,
"MooseX::Types::Locale::Codes::Country".
coerce CountryCode,
from CountryName,
...
CountryCode->coerce($country_name_from_alpha_2);
See "case2_name_to_code.t".
Also, I confirmed that all country names from all code sets don't conflict
with all country codes by test cases.
See "case2_name_does_not_conflict_with_code.t".
By the way, you wouldn't want coercion from name (on some code set) into
code
(on "other" code set), would you?
(CountryCode['alpha-3'])->coerce($country_name_from_alpha_2);
Case 3. aliased name to canonical name
--------------------------------------
* concrete example: CountryName->check('Great Britain')
* current result: false
* coming result: false
* concrete example: CountryName->coerce('Great Britain')
* current result: 'United Kingdom'
* coming result: 'United Kingdom'
I did it on the current module and the succeeding module,
"MooseX::Types::Locale::Codes::Country".
See "case3_alias_to_name.t".
Case 4. code to name
--------------------
* concrete example: CountryName->coerce('JP')
* current result: 'JP'
* coming result: (I have no suggestion yet)
* Do you want 'Japan'?
You didn't refer to the conversion, but it is.
See "case4_code_to_name.t".
In my humble opinion, there is low demand for the "reverse" coercion.
Could you, an user of the module, tell me about your demand?
Also, I confirmed that all country codes from all code sets don't conflict
with all country names by test cases.
See "case4_code_does_not_conflict_with_name.t".
Regards,
--
MORIYA Masaki, alias Gardejo