| 1 | package WiX3::XML::DirectoryRef; | ||
| 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 ); | ||
| 12 | use MooseX::Types::Moose qw( Int Str ArrayRef ); | ||
| 13 | use WiX3::XML::TagTypes qw( DirectoryRefChildTag DirectoryTag ); | ||
| 14 | use WiX3::Util::StrictConstructor; | ||
| 15 | |||
| 16 | our $VERSION = '0.011'; | ||
| 17 | |||
| 18 | with qw(WiX3::XML::Role::TagAllowsChildTags | ||
| 19 | WiX3::Role::Traceable | ||
| 20 | ); | ||
| 21 | |||
| 22 | ## Allows Component, Directory, Merge as children. | ||
| 23 | |||
| 24 | has '+child_tags' => ( isa => ArrayRef [DirectoryRefChildTag] ); | ||
| 25 | |||
| 26 | |||
| 27 | ##################################################################### | ||
| 28 | # Accessors: | ||
| 29 | # None. | ||
| 30 | |||
| 31 | has directory_object => ( | ||
| 32 | is => 'ro', | ||
| 33 | isa => DirectoryTag, | ||
| 34 | reader => '_get_directory_object', | ||
| 35 | required => 1, | ||
| 36 | weak_ref => 1, | ||
| 37 | handles => [qw(get_path get_directory_id)], | ||
| 38 | ); | ||
| 39 | |||
| 40 | has diskid => ( | ||
| 41 | is => 'ro', | ||
| 42 | isa => Int, | ||
| 43 | reader => '_get_diskid', | ||
| 44 | ); | ||
| 45 | |||
| 46 | has filesource => ( | ||
| 47 | is => 'ro', | ||
| 48 | isa => Str, | ||
| 49 | reader => '_get_filesource', | ||
| 50 | ); | ||
| 51 | |||
| 52 | ##################################################################### | ||
| 53 | # Methods to implement the Tag role. | ||
| 54 | |||
| 55 | sub BUILDARGS { | ||
| 56 | my $class = shift; | ||
| 57 | |||
| 58 | if ( @_ == 1 && _INSTANCE( $_[0], 'WiX3::XML::Directory' ) ) { | ||
| 59 | return { directory_object => $_[0] }; | ||
| 60 | } else { | ||
| 61 | return $class->SUPER::BUILDARGS(@_); | ||
| 62 | } | ||
| 63 | } | ||
| 64 | |||
| 65 | |||
| 66 | sub as_string { | ||
| 67 | my $self = shift; | ||
| 68 | |||
| 69 | my $children = $self->has_child_tags(); | ||
| 70 | my $tags; | ||
| 71 | $tags = $self->print_attribute( 'Id', $self->get_directory_id() ); | ||
| 72 | $tags .= $self->print_attribute( 'DiskId', $self->_get_diskid() ); | ||
| 73 | $tags .= | ||
| 74 | $self->print_attribute( 'FileSource', $self->_get_filesource() ); | ||
| 75 | |||
| 76 | if ($children) { | ||
| 77 | my $child_string = $self->as_string_children(); | ||
| 78 | return qq{<DirectoryRef$tags>\n$child_string\n</DirectoryRef>\n}; | ||
| 79 | } else { | ||
| 80 | return qq{<DirectoryRef$tags />\n}; | ||
| 81 | } | ||
| 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__ |