| 1 | package CSAF::Base; | ||
| 2 | |||
| 3 | use 5.010001; | ||
| 4 | use strict; | ||
| 5 | use warnings; | ||
| 6 | use utf8; | ||
| 7 | |||
| 8 | use Carp; | ||
| 9 | use Moo; | ||
| 10 | |||
| 11 | around BUILDARGS => sub { | ||
| 12 | |||
| 13 | my ($orig, $class, @args) = @_; | ||
| 14 | |||
| 15 | return {csaf => $args[0]} if @args == 1; | ||
| 16 | return $class->$orig(@args); | ||
| 17 | |||
| 18 | }; | ||
| 19 | |||
| 20 | has csaf => ( | ||
| 21 | is => 'ro', | ||
| 22 | isa => sub { | ||
| 23 | Carp::croak 'Must be an instance of "CSAF"' unless ref($_[0]) eq 'CSAF'; | ||
| 24 | }, | ||
| 25 | required => 1 | ||
| 26 | ); | ||
| 27 | |||
| 28 | sub clone { | ||
| 29 | |||
| 30 | my $self = shift; | ||
| 31 | my $clone = {%$self}; | ||
| 32 | |||
| 33 | bless $clone, ref $self; | ||
| 34 | return $clone; | ||
| 35 | |||
| 36 | } | ||
| 37 | |||
| 38 | 1; | ||
| 39 | |||
| 40 | __END__ |