| 1 | package # Hide from PAUSE | ||
| 2 | WiX3::XML::GeneratesGUID::Object; | ||
| 3 | |||
| 4 | use 5.008003; | ||
| 5 | |||
| 6 | #use metaclass ( | ||
| 7 | # base_class => 'MooseX::Singleton::Object', | ||
| 8 | # metaclass => 'MooseX::Singleton::Meta::Class', | ||
| 9 | # error_class => 'WiX3::Util::Error', | ||
| 10 | #); | ||
| 11 | use MooseX::Singleton; | ||
| 12 | use Data::UUID qw( NameSpace_DNS ); | ||
| 13 | use WiX3::Types qw( Host ); | ||
| 14 | require WiX3::Exceptions; | ||
| 15 | |||
| 16 | our $VERSION = '0.011'; | ||
| 17 | |||
| 18 | |||
| 19 | ##################################################################### | ||
| 20 | # Attributes | ||
| 21 | |||
| 22 | with 'WiX3::Role::Traceable'; | ||
| 23 | |||
| 24 | has _sitename => ( | ||
| 25 | is => 'ro', | ||
| 26 | isa => Host, | ||
| 27 | reader => '_get_sitename', | ||
| 28 | default => q{www.perl.invalid}, | ||
| 29 | ); | ||
| 30 | |||
| 31 | has _guidgen => ( | ||
| 32 | is => 'ro', | ||
| 33 | isa => 'Data::UUID', | ||
| 34 | reader => '_get_guidgen', | ||
| 35 | init_arg => undef, | ||
| 36 | default => sub { | ||
| 37 | return Data::UUID->new(); | ||
| 38 | }, | ||
| 39 | ); | ||
| 40 | |||
| 41 | has _sitename_guid => ( | ||
| 42 | is => 'ro', | ||
| 43 | isa => 'Str', | ||
| 44 | reader => '_get_sitename_guid', | ||
| 45 | lazy => 1, | ||
| 46 | init_arg => undef, | ||
| 47 | default => sub { | ||
| 48 | my $self = shift; | ||
| 49 | |||
| 50 | my $guidgen = $self->_get_guidgen(); | ||
| 51 | |||
| 52 | my $guid = | ||
| 53 | $guidgen->create_from_name( Data::UUID::NameSpace_DNS, | ||
| 54 | $self->_get_sitename() ); | ||
| 55 | |||
| 56 | $self->trace_line( | ||
| 57 | 5, ## no critic(ProhibitMagicNumbers) | ||
| 58 | 'Generated site GUID: ' . $guidgen->to_string($guid) . "\n" | ||
| 59 | ); | ||
| 60 | |||
| 61 | return $guid; | ||
| 62 | }, | ||
| 63 | ); | ||
| 64 | |||
| 65 | ##################################################################### | ||
| 66 | # Accessors | ||
| 67 | |||
| 68 | ##################################################################### | ||
| 69 | # Main Methods | ||
| 70 | |||
| 71 | ######################################## | ||
| 72 | # generate_guid($id) | ||
| 73 | # Parameters: | ||
| 74 | # $id: ID to create a GUID for. | ||
| 75 | # Returns: | ||
| 76 | # The GUID generated. | ||
| 77 | |||
| 78 | sub generate_guid { | ||
| 79 | my ( $self, $id ) = @_; | ||
| 80 | |||
| 81 | #... then use it to create a GUID out of the filename. | ||
| 82 | return | ||
| 83 | uc $self->_get_guidgen() | ||
| 84 | ->create_from_name_str( $self->_get_sitename_guid(), $id ); | ||
| 85 | |||
| 86 | } | ||
| 87 | |||
| 88 | __PACKAGE__->meta->make_immutable; | ||
| 89 | no MooseX::Singleton; | ||
| 90 | |||
| 91 | 1; |