| 1 | package WiX3::XML::Fragment::CreateFolder; | ||
| 2 | |||
| 3 | use 5.008003; | ||
| 4 | use Moose 2; | ||
| 5 | use Params::Util qw( _IDENTIFIER ); | ||
| 6 | |||
| 7 | our $VERSION = '0.011'; | ||
| 8 | |||
| 9 | with 'WiX3::XML::Role::Fragment'; | ||
| 10 | |||
| 11 | has _tag => ( | ||
| 12 | is => 'ro', | ||
| 13 | isa => 'WiX3::XML::Fragment', | ||
| 14 | reader => '_get_tag', | ||
| 15 | handles => [qw(search_file check_duplicates get_directory_id)], | ||
| 16 | ); | ||
| 17 | |||
| 18 | ##################################################################### | ||
| 19 | # Constructor for CreateFolderFragment | ||
| 20 | # | ||
| 21 | # Parameters: [pairs] | ||
| 22 | # id, directory: See Base::Fragment. | ||
| 23 | |||
| 24 | sub BUILDARGS { | ||
| 25 | my $class = shift; | ||
| 26 | my ( $id, $directory_id ); | ||
| 27 | |||
| 28 | if ( @_ == 2 && !ref $_[0] ) { | ||
| 29 | $id = $_[0]; | ||
| 30 | $directory_id = $_[1]; | ||
| 31 | } elsif ( @_ == 1 && 'HASH' eq ref $_[0] ) { | ||
| 32 | my %args = %{ $_[0] }; | ||
| 33 | $id = $args{'id'}; | ||
| 34 | $directory_id = $args{'directory_id'}; | ||
| 35 | } elsif ( @_ == ( 2 * 2 ) ) { # 2 pairs. | ||
| 36 | my %args = {@_}; | ||
| 37 | $id = $args{'id'}; | ||
| 38 | $directory_id = $args{'directory_id'}; | ||
| 39 | } else { | ||
| 40 | WiX3::Exception::Parameter::Odd->throw(); | ||
| 41 | } | ||
| 42 | |||
| 43 | if ( not defined $id ) { | ||
| 44 | WiX3::Exception::Parameter::Missing->throw('id'); | ||
| 45 | } | ||
| 46 | |||
| 47 | if ( not defined $directory_id ) { | ||
| 48 | WiX3::Exception::Parameter::Missing->throw('directory_id'); | ||
| 49 | } | ||
| 50 | |||
| 51 | if ( not _IDENTIFIER($id) ) { | ||
| 52 | WiX3::Exception::Parameter::Invalid->throw('id'); | ||
| 53 | } | ||
| 54 | |||
| 55 | if ( not _IDENTIFIER($directory_id) ) { | ||
| 56 | WiX3::Exception::Parameter::Invalid->throw('directory_id'); | ||
| 57 | } | ||
| 58 | |||
| 59 | my $tag1 = WiX3::XML::Fragment->new( id => "Create$id" ); | ||
| 60 | my $tag2 = WiX3::XML::DirectoryRef->new( id => $directory_id ); | ||
| 61 | my $tag3 = WiX3::XML::Component->new( id => "Create$id" ); | ||
| 62 | my $tag4 = WiX3::XML::CreateFolder->new(); | ||
| 63 | |||
| 64 | $tag3->add_tag($tag4); | ||
| 65 | $tag2->add_tag($tag3); | ||
| 66 | $tag1->add_tag($tag2); | ||
| 67 | |||
| 68 | return { '_tag' => $tag1 }; | ||
| 69 | } ## end sub BUILDARGS | ||
| 70 | |||
| 71 | sub BUILD { | ||
| 72 | my $self = shift; | ||
| 73 | |||
| 74 | my $directory_id = $self->get_directory_id(); | ||
| 75 | |||
| 76 | $self->trace_line( 2, | ||
| 77 | 'Creating directory creation entry for directory ' | ||
| 78 | . "id $directory_id\n" ); | ||
| 79 | |||
| 80 | return; | ||
| 81 | } | ||
| 82 | |||
| 83 | sub as_string { | ||
| 84 | my $self = shift; | ||
| 85 | |||
| 86 | return $self->_get_tag()->as_string(); | ||
| 87 | } | ||
| 88 | |||
| 89 | sub get_namespace { | ||
| 90 | return q{xmlns='http://schemas.microsoft.com/wix/2006/wi'}; | ||
| 91 | } | ||
| 92 | |||
| 93 | # Needs no regeneration. | ||
| 94 | sub regenerate { | ||
| 95 | return; | ||
| 96 | } | ||
| 97 | |||
| 98 | 1; | ||
| 99 | |||
| 100 | __END__ |