| 1 | package WiX3::XML::ComponentRef; | ||
| 2 | |||
| 3 | use 5.008003; | ||
| 4 | |||
| 5 | # Must be done before Moose, or it won't get picked up. | ||
| 6 | use metaclass ( | ||
| 7 | metaclass => 'Moose::Meta::Class', | ||
| 8 | error_class => 'WiX3::Util::Error', | ||
| 9 | ); | ||
| 10 | use Moose 2; | ||
| 11 | use Params::Util qw( _INSTANCE _IDENTIFIER ); | ||
| 12 | use MooseX::Types::Moose qw( Str Maybe ); | ||
| 13 | use WiX3::Types qw( YesNoType ); | ||
| 14 | use WiX3::Util::StrictConstructor; | ||
| 15 | |||
| 16 | our $VERSION = '0.011'; | ||
| 17 | |||
| 18 | # http://wix.sourceforge.net/manual-wix3/wix_xsd_componentref.htm | ||
| 19 | |||
| 20 | with 'WiX3::XML::Role::Tag'; | ||
| 21 | |||
| 22 | ## Allows no child tags. | ||
| 23 | |||
| 24 | has id => ( | ||
| 25 | is => 'ro', | ||
| 26 | isa => Str, | ||
| 27 | reader => 'get_id', | ||
| 28 | required => 1, | ||
| 29 | ); | ||
| 30 | |||
| 31 | has primary => ( | ||
| 32 | is => 'ro', | ||
| 33 | isa => Maybe [YesNoType], | ||
| 34 | reader => '_get_primary', | ||
| 35 | default => undef, | ||
| 36 | ); | ||
| 37 | |||
| 38 | ##################################################################### | ||
| 39 | # Constructor shortcuts. | ||
| 40 | |||
| 41 | sub BUILDARGS { | ||
| 42 | my $class = shift; | ||
| 43 | my $id; | ||
| 44 | |||
| 45 | if ( @_ == 1 && !ref $_[0] ) { | ||
| 46 | $id = $_[0]; | ||
| 47 | } elsif ( @_ == 1 && _INSTANCE( $_[0], 'WiX3::XML::Component' ) ) { | ||
| 48 | $id = $_[0]->get_id(); | ||
| 49 | } else { | ||
| 50 | return $class->SUPER::BUILDARGS(@_); | ||
| 51 | } | ||
| 52 | |||
| 53 | if ( not defined $id ) { | ||
| 54 | WiX3::Exception::Parameter::Missing->throw('id'); | ||
| 55 | } | ||
| 56 | |||
| 57 | if ( not defined _IDENTIFIER("C_$id") ) { | ||
| 58 | print "Invalid ID: $id\n"; | ||
| 59 | WiX3::Exception::Parameter::Invalid->throw('id'); | ||
| 60 | } | ||
| 61 | |||
| 62 | return { 'id' => $id }; | ||
| 63 | } ## end sub BUILDARGS | ||
| 64 | |||
| 65 | |||
| 66 | ##################################################################### | ||
| 67 | # Methods to implement the Tag role. | ||
| 68 | |||
| 69 | sub as_string { | ||
| 70 | my $self = shift; | ||
| 71 | |||
| 72 | my $id = 'C_' . $self->get_id(); | ||
| 73 | |||
| 74 | # Print tag. | ||
| 75 | my $answer; | ||
| 76 | $answer = '<ComponentRef'; | ||
| 77 | $answer .= $self->print_attribute( 'Id', $id ); | ||
| 78 | $answer .= $self->print_attribute( 'Primary', $self->_get_primary() ); | ||
| 79 | $answer .= " />\n"; | ||
| 80 | |||
| 81 | return $answer; | ||
| 82 | } ## end sub as_string | ||
| 83 | |||
| 84 | sub get_namespace { | ||
| 85 | return q{xmlns='http://schemas.microsoft.com/wix/2006/wi'}; | ||
| 86 | } | ||
| 87 | |||
| 88 | no Moose; | ||
| 89 | __PACKAGE__->meta->make_immutable; | ||
| 90 | |||
| 91 | 1; | ||
| 92 | |||
| 93 | __END__ |