| 1 | package WiX3::XML::RegistryValue; | ||
| 2 | |||
| 3 | #################################################################### | ||
| 4 | # WiX3::XML::RegistryValue - Object that represents an <RegistryValue> tag. | ||
| 5 | # | ||
| 6 | # Copyright 2010 Curtis Jewell, Alexandr Ciornii | ||
| 7 | # | ||
| 8 | # License is the same as perl. See WiX3.pm for details. | ||
| 9 | # | ||
| 10 | use 5.008003; | ||
| 11 | |||
| 12 | # Must be done before Moose, or it won't get picked up. | ||
| 13 | use metaclass ( | ||
| 14 | metaclass => 'Moose::Meta::Class', | ||
| 15 | error_class => 'WiX3::Util::Error', | ||
| 16 | ); | ||
| 17 | use Moose 2; | ||
| 18 | use Params::Util qw( _IDENTIFIER _STRING ); | ||
| 19 | use WiX3::Types | ||
| 20 | qw( YesNoType EnumRegistryRootType EnumRegistryValueType EnumRegistryValueAction ); | ||
| 21 | use MooseX::Types::Moose qw( Str Maybe Bool Undef ); | ||
| 22 | use WiX3::Util::StrictConstructor; | ||
| 23 | |||
| 24 | our $VERSION = '0.011'; | ||
| 25 | |||
| 26 | # http://wix.sourceforge.net/manual-wix3/wix_xsd_registryvalue.htm | ||
| 27 | |||
| 28 | with 'WiX3::XML::Role::Tag'; | ||
| 29 | |||
| 30 | # No child tags allowed. | ||
| 31 | |||
| 32 | ##################################################################### | ||
| 33 | # Accessors: | ||
| 34 | # see new. | ||
| 35 | |||
| 36 | has id => ( | ||
| 37 | is => 'ro', | ||
| 38 | isa => Str, | ||
| 39 | reader => 'get_id', | ||
| 40 | required => 1, | ||
| 41 | ); | ||
| 42 | |||
| 43 | has root => ( | ||
| 44 | is => 'ro', | ||
| 45 | isa => EnumRegistryRootType, | ||
| 46 | reader => '_get_root', | ||
| 47 | ); | ||
| 48 | |||
| 49 | has key => ( | ||
| 50 | is => 'ro', | ||
| 51 | isa => Maybe [Str], | ||
| 52 | reader => '_get_key', | ||
| 53 | ); | ||
| 54 | |||
| 55 | has action => ( | ||
| 56 | is => 'ro', | ||
| 57 | isa => EnumRegistryValueAction, | ||
| 58 | reader => '_get_action', | ||
| 59 | default => 'write', | ||
| 60 | ); | ||
| 61 | |||
| 62 | has key_path => ( | ||
| 63 | is => 'ro', | ||
| 64 | isa => YesNoType | Undef, | ||
| 65 | reader => '_get_key_path', | ||
| 66 | |||
| 67 | # default => 'no', | ||
| 68 | coerce => 1, | ||
| 69 | ); | ||
| 70 | |||
| 71 | has type => ( | ||
| 72 | is => 'ro', | ||
| 73 | isa => EnumRegistryValueType, | ||
| 74 | reader => '_get_type', | ||
| 75 | required => 1, | ||
| 76 | ); | ||
| 77 | |||
| 78 | has value => ( | ||
| 79 | is => 'ro', | ||
| 80 | isa => Str, | ||
| 81 | reader => '_get_value', | ||
| 82 | ); | ||
| 83 | |||
| 84 | ##################################################################### | ||
| 85 | # Main Methods | ||
| 86 | |||
| 87 | ######################################## | ||
| 88 | # as_string | ||
| 89 | # Parameters: | ||
| 90 | # None. | ||
| 91 | # Returns: | ||
| 92 | # String containing <RegistryValue> tag defined by this object. | ||
| 93 | |||
| 94 | sub as_string { | ||
| 95 | my $self = shift; | ||
| 96 | |||
| 97 | my $id = 'RV_' . $self->get_id(); | ||
| 98 | my $type = $self->_get_type(); | ||
| 99 | my $value = $self->_get_value(); | ||
| 100 | |||
| 101 | # Print tag. | ||
| 102 | my $string = '<RegistryValue'; | ||
| 103 | |||
| 104 | my @attribute = ( | ||
| 105 | [ 'Id' => $id, ], | ||
| 106 | [ 'Root' => $self->_get_root(), ], | ||
| 107 | [ 'Key' => $self->_get_key(), ], | ||
| 108 | [ 'Action' => $self->_get_action(), ], | ||
| 109 | [ 'KeyPath' => $self->_get_key_path(), ], | ||
| 110 | [ 'Type' => $self->_get_type(), ], | ||
| 111 | ); | ||
| 112 | |||
| 113 | my ( $k, $v ); | ||
| 114 | |||
| 115 | foreach my $ref (@attribute) { | ||
| 116 | ( $k, $v ) = @{$ref}; | ||
| 117 | $string .= $self->print_attribute( $k, $v ); | ||
| 118 | } | ||
| 119 | |||
| 120 | if ( 'multiString' eq $type ) { | ||
| 121 | $string .= qq{>$value</RegistryValue>\n}; | ||
| 122 | } else { | ||
| 123 | $string .= $self->print_attribute( 'Value', $value ); | ||
| 124 | $string .= qq{ />\n}; | ||
| 125 | } | ||
| 126 | |||
| 127 | return $string; | ||
| 128 | } ## end sub as_string | ||
| 129 | |||
| 130 | sub get_namespace { | ||
| 131 | return q{xmlns='http://schemas.microsoft.com/wix/2006/wi'}; | ||
| 132 | } | ||
| 133 | |||
| 134 | no Moose; | ||
| 135 | __PACKAGE__->meta->make_immutable; | ||
| 136 | |||
| 137 | 1; |