File: uuid.pm

package info (click to toggle)
libcatmandu-identifier-perl 0.15-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 292 kB
  • sloc: perl: 978; makefile: 2
file content (42 lines) | stat: -rw-r--r-- 700 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package Catmandu::Fix::uuid;

our $VERSION = '0.15';

use Catmandu::Sane;
use Data::UUID::MT;
use Moo;
use Catmandu::Fix::Has;

with 'Catmandu::Fix::Base';

has path => (fix_arg => 1);

sub emit {
    my ($self, $fixer) = @_;
    my $path = $fixer->split_path($self->path);

    $fixer->emit_create_path(
        $fixer->var,
        $path,
        sub {
            my $var = shift;
            "${var} = Data::UUID::MT->new(version => 4)->create_string;";
        }
    );
}

=head1 NAME

Catmandu::Fix::uuid - create a Globally/Universally Unique Identifier

=head1 SYNOPSIS

  uuid(my.field) # my => {field => '4162F712-1DD2-11B2-B17E-C09EFE1DC403' }

=head1 SEE ALSO

L<Catmandu::Fix>

=cut

1;