| 1 | package WiX3::XML::FeatureRef; | ||
| 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 ArrayRef ); | ||
| 13 | use WiX3::Types qw( YesNoType ); | ||
| 14 | use WiX3::XML::TagTypes qw( FeatureRefChildTag ); | ||
| 15 | use WiX3::Util::StrictConstructor; | ||
| 16 | |||
| 17 | our $VERSION = '0.011'; | ||
| 18 | |||
| 19 | # http://wix.sourceforge.net/manual-wix3/wix_xsd_featureref.htm | ||
| 20 | |||
| 21 | with qw(WiX3::XML::Role::TagAllowsChildTags); | ||
| 22 | |||
| 23 | ## Allows Component, ComponentGroupRef, ComponentRef, Feature, | ||
| 24 | ## FeatureGroup, FeatureGroupRef, FeatureRef, MergeRef. | ||
| 25 | |||
| 26 | ## FeatureRefChildTag allows Component, ComponentRef, Feature, FeatureRef, | ||
| 27 | ## and MergeRef at the moment. | ||
| 28 | |||
| 29 | has '+child_tags' => ( isa => ArrayRef [FeatureRefChildTag] ); | ||
| 30 | |||
| 31 | |||
| 32 | has id => ( | ||
| 33 | is => 'ro', | ||
| 34 | isa => Str, | ||
| 35 | reader => 'get_id', | ||
| 36 | required => 1, | ||
| 37 | ); | ||
| 38 | |||
| 39 | has ignoreparent => ( | ||
| 40 | is => 'ro', | ||
| 41 | isa => Maybe [YesNoType], | ||
| 42 | reader => '_get_ignoreparent', | ||
| 43 | default => undef, | ||
| 44 | ); | ||
| 45 | |||
| 46 | ##################################################################### | ||
| 47 | # Constructor shortcuts. | ||
| 48 | |||
| 49 | sub BUILDARGS { | ||
| 50 | my $class = shift; | ||
| 51 | my $id; | ||
| 52 | |||
| 53 | if ( @_ == 1 && !ref $_[0] ) { | ||
| 54 | $id = $_[0]; | ||
| 55 | } elsif ( @_ == 1 && _INSTANCE( $_[0], 'WiX3::XML::Feature' ) ) { | ||
| 56 | $id = $_[0]->get_id(); | ||
| 57 | } else { | ||
| 58 | return $class->SUPER::BUILDARGS(@_); | ||
| 59 | } | ||
| 60 | |||
| 61 | if ( not defined $id ) { | ||
| 62 | WiX3::Exception::Parameter::Missing->throw('id'); | ||
| 63 | } | ||
| 64 | |||
| 65 | if ( not defined _IDENTIFIER($id) ) { | ||
| 66 | WiX3::Exception::Parameter::Invalid->throw('id'); | ||
| 67 | } | ||
| 68 | |||
| 69 | return { 'id' => $id }; | ||
| 70 | } ## end sub BUILDARGS | ||
| 71 | |||
| 72 | |||
| 73 | ##################################################################### | ||
| 74 | # Methods to implement the Tag role. | ||
| 75 | |||
| 76 | |||
| 77 | # TODO: Handle children. | ||
| 78 | sub as_string { | ||
| 79 | my $self = shift; | ||
| 80 | |||
| 81 | my $id = 'Feat_' . $self->get_id(); | ||
| 82 | |||
| 83 | # Print tag. | ||
| 84 | my $answer; | ||
| 85 | $answer = '<FeatureRef'; | ||
| 86 | $answer .= $self->print_attribute( 'Id', $id ); | ||
| 87 | $answer .= | ||
| 88 | $self->print_attribute( 'IgnoreParent', $self->_get_ignoreparent() ); | ||
| 89 | $answer .= " />\n"; | ||
| 90 | |||
| 91 | return $answer; | ||
| 92 | } ## end sub as_string | ||
| 93 | |||
| 94 | sub get_namespace { | ||
| 95 | return q{xmlns='http://schemas.microsoft.com/wix/2006/wi'}; | ||
| 96 | } | ||
| 97 | |||
| 98 | no Moose; | ||
| 99 | __PACKAGE__->meta->make_immutable; | ||
| 100 | |||
| 101 | 1; | ||
| 102 | |||
| 103 | __END__ |