| 1 | package WiX3::XML::Environment; | ||
| 2 | |||
| 3 | #################################################################### | ||
| 4 | # WiX3::XML::Environment - Object that represents an <Environment> tag. | ||
| 5 | # | ||
| 6 | # Copyright 2009, 2010 Curtis Jewell | ||
| 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 qw( YesNoType EnumEnvironmentAction); | ||
| 20 | use MooseX::Types::Moose qw( Str Maybe ); | ||
| 21 | use WiX3::Util::StrictConstructor; | ||
| 22 | |||
| 23 | our $VERSION = '0.011'; | ||
| 24 | |||
| 25 | # http://wix.sourceforge.net/manual-wix3/wix_xsd_environment.htm | ||
| 26 | |||
| 27 | with 'WiX3::XML::Role::Tag'; | ||
| 28 | |||
| 29 | # No child tags allowed. | ||
| 30 | |||
| 31 | ##################################################################### | ||
| 32 | # Accessors: | ||
| 33 | # see new. | ||
| 34 | |||
| 35 | has id => ( | ||
| 36 | is => 'ro', | ||
| 37 | isa => Str, | ||
| 38 | reader => 'get_id', | ||
| 39 | required => 1, | ||
| 40 | ); | ||
| 41 | |||
| 42 | has name => ( | ||
| 43 | is => 'ro', | ||
| 44 | isa => Str, | ||
| 45 | reader => '_get_name', | ||
| 46 | required => 1, | ||
| 47 | ); | ||
| 48 | |||
| 49 | has value => ( | ||
| 50 | is => 'ro', | ||
| 51 | isa => Str, | ||
| 52 | reader => '_get_value', | ||
| 53 | ); | ||
| 54 | |||
| 55 | # TODO: These two are enums. Define types accordingly. | ||
| 56 | # Note: see http://wix.sourceforge.net/manual-wix3/wix_xsd_environment.htm for valid values. | ||
| 57 | |||
| 58 | has action => ( | ||
| 59 | is => 'ro', | ||
| 60 | isa => EnumEnvironmentAction, | ||
| 61 | reader => '_get_action', | ||
| 62 | default => 'set', | ||
| 63 | ); | ||
| 64 | |||
| 65 | has part => ( | ||
| 66 | is => 'ro', | ||
| 67 | isa => Str, | ||
| 68 | reader => '_get_part', | ||
| 69 | default => 'all', | ||
| 70 | ); | ||
| 71 | |||
| 72 | has permanent => ( | ||
| 73 | is => 'ro', | ||
| 74 | isa => YesNoType, | ||
| 75 | reader => '_get_permanent', | ||
| 76 | default => 'yes', | ||
| 77 | ); | ||
| 78 | |||
| 79 | has system => ( | ||
| 80 | is => 'ro', | ||
| 81 | isa => YesNoType, | ||
| 82 | reader => '_get_system', | ||
| 83 | default => 'yes', | ||
| 84 | ); | ||
| 85 | |||
| 86 | has separator => ( | ||
| 87 | is => 'ro', | ||
| 88 | isa => Maybe [Str], | ||
| 89 | reader => '_get_separator', | ||
| 90 | default => undef, | ||
| 91 | |||
| 92 | # default => ';', WiX defaults to this if not included | ||
| 93 | ); | ||
| 94 | |||
| 95 | ##################################################################### | ||
| 96 | # Main Methods | ||
| 97 | |||
| 98 | ######################################## | ||
| 99 | # as_string | ||
| 100 | # Parameters: | ||
| 101 | # None. | ||
| 102 | # Returns: | ||
| 103 | # String containing <Environment> tag defined by this object. | ||
| 104 | |||
| 105 | sub as_string { | ||
| 106 | my $self = shift; | ||
| 107 | |||
| 108 | my $id = 'E_' . $self->get_id(); | ||
| 109 | |||
| 110 | # Print tag. | ||
| 111 | my $answer; | ||
| 112 | $answer = '<Environment'; | ||
| 113 | $answer .= $self->print_attribute( 'Id', $id ); | ||
| 114 | $answer .= $self->print_attribute( 'Name', $self->_get_name() ); | ||
| 115 | $answer .= $self->print_attribute( 'Value', $self->_get_value() ); | ||
| 116 | $answer .= $self->print_attribute( 'System', $self->_get_system() ); | ||
| 117 | $answer .= | ||
| 118 | $self->print_attribute( 'Permanent', $self->_get_permanent() ); | ||
| 119 | $answer .= $self->print_attribute( 'Action', $self->_get_action() ); | ||
| 120 | $answer .= $self->print_attribute( 'Part', $self->_get_part() ); | ||
| 121 | $answer .= | ||
| 122 | $self->print_attribute( 'Separator', $self->_get_separator() ); | ||
| 123 | $answer .= " />\n"; | ||
| 124 | |||
| 125 | return $answer; | ||
| 126 | } ## end sub as_string | ||
| 127 | |||
| 128 | sub get_namespace { | ||
| 129 | return q{xmlns='http://schemas.microsoft.com/wix/2006/wi'}; | ||
| 130 | } | ||
| 131 | |||
| 132 | no Moose; | ||
| 133 | __PACKAGE__->meta->make_immutable; | ||
| 134 | |||
| 135 | 1; |