| 1 | package # Hide from PAUSE. | ||
| 2 | WiX3::Types; | ||
| 3 | |||
| 4 | use 5.008003; | ||
| 5 | use MooseX::Types -declare => [ qw( | ||
| 6 | Host Tracelevel IsTag _YesNoType YesNoType ComponentGuidType PositiveInt | ||
| 7 | NonNegativeInt TraceObject | ||
| 8 | EnumRemoveFolderOn EnumEnvironmentAction EnumRegistryKeyAction | ||
| 9 | EnumRegistryValueType EnumRegistryRootType EnumRegistryValueAction | ||
| 10 | ) ]; | ||
| 11 | use Regexp::Common 2.105; | ||
| 12 | use MooseX::Types::Moose qw( Str Int Bool HashRef ); | ||
| 13 | use Readonly 1.03 qw( Readonly ); | ||
| 14 | |||
| 15 | our $VERSION = '0.011'; | ||
| 16 | |||
| 17 | # Assemble the GUID regex from pieces. | ||
| 18 | Readonly my $HEX => '0-9A-F'; | ||
| 19 | Readonly my $GUID_MIDDLE_PART => "[$HEX]{4}"; | ||
| 20 | Readonly my $GUID_MIDDLE => | ||
| 21 | "[-] $GUID_MIDDLE_PART [-] $GUID_MIDDLE_PART [-] $GUID_MIDDLE_PART [-]"; | ||
| 22 | Readonly my $GUID_BEGINNING => "[$HEX]{8}"; | ||
| 23 | Readonly my $GUID_END => "[$HEX]{12}"; | ||
| 24 | Readonly my $GUID_OPEN => '\A [{(]?'; | ||
| 25 | Readonly my $GUID_CLOSE => '[})]? \z'; | ||
| 26 | Readonly my $GUID_QR => | ||
| 27 | qr{$GUID_OPEN $GUID_BEGINNING $GUID_MIDDLE $GUID_END $GUID_CLOSE}msx; | ||
| 28 | |||
| 29 | subtype Host, as Str, where { | ||
| 30 | $_ =~ /\A $RE{net}{IPv4} \z/msx | ||
| 31 | or $_ =~ /\A $RE{net}{domain}{-nospace} \z/msx; | ||
| 32 | }, message { | ||
| 33 | "$_ is not a valid hostname"; | ||
| 34 | }; | ||
| 35 | |||
| 36 | enum EnumRemoveFolderOn, qw( install uninstall both ); | ||
| 37 | |||
| 38 | enum EnumEnvironmentAction, qw( create set remove ); | ||
| 39 | |||
| 40 | enum EnumRegistryKeyAction, qw( create createAndRemoveOnUninstall none ); | ||
| 41 | |||
| 42 | enum EnumRegistryRootType, qw( HKMU HKCR HKCU HKLM HKU ); | ||
| 43 | |||
| 44 | enum EnumRegistryValueType, | ||
| 45 | qw( string integer binary expandable multiString ); | ||
| 46 | |||
| 47 | enum EnumRegistryValueAction, qw( append prepend write ); | ||
| 48 | |||
| 49 | subtype IsTag, as role_type 'WiX3::XML::Role::Tag'; | ||
| 50 | |||
| 51 | subtype TraceObject, as class_type 'WiX3::Trace::Object'; | ||
| 52 | |||
| 53 | subtype Tracelevel, | ||
| 54 | as Int, | ||
| 55 | where { ( $_ >= 0 ) && ( $_ <= 5 ) }, ## no critic (ProhibitMagicNumbers) | ||
| 56 | message {"The tracelevel you provided, $_, was not valid."}; | ||
| 57 | |||
| 58 | subtype _YesNoType, | ||
| 59 | as Str, | ||
| 60 | where { ( lc $_ eq 'yes' ) or ( lc $_ eq 'no' ); }, | ||
| 61 | message {"$_ is not yes or no"}; | ||
| 62 | |||
| 63 | subtype YesNoType, | ||
| 64 | as _YesNoType, | ||
| 65 | where { ( $_ eq 'yes' ) or ( $_ eq 'no' ); }, | ||
| 66 | message {"$_ is not yes or no"}; | ||
| 67 | |||
| 68 | coerce YesNoType, from _YesNoType, via { lc $_ }; | ||
| 69 | |||
| 70 | coerce YesNoType, from Bool | Int, via { $_ ? 'yes' : 'no' }; | ||
| 71 | |||
| 72 | subtype ComponentGuidType, as Str, where { | ||
| 73 | $_ =~ $GUID_QR; | ||
| 74 | }, message { | ||
| 75 | "$_ is not a GUID"; | ||
| 76 | }; | ||
| 77 | |||
| 78 | subtype PositiveInt, | ||
| 79 | as Int, | ||
| 80 | where { $_ > 0 }, | ||
| 81 | message {'Number is not larger than 0'}; | ||
| 82 | |||
| 83 | subtype NonNegativeInt, | ||
| 84 | as Int, | ||
| 85 | where { $_ >= 0 }, | ||
| 86 | message {'Number is smaller than 0'}; | ||
| 87 | |||
| 88 | # type coercion | ||
| 89 | coerce PositiveInt, from Int, via {1}; | ||
| 90 | |||
| 91 | # type coercion | ||
| 92 | coerce NonNegativeInt, from Int, via {1}; | ||
| 93 | |||
| 94 | 1; # Magic true value required at end of module |