| 1 | package SPVM::Cloner; | ||
| 2 | |||
| 3 | 1; | ||
| 4 | |||
| 5 | =head1 Name | ||
| 6 | |||
| 7 | SPVM::Cloner - Interface Type for the Callback to Clone a Object | ||
| 8 | |||
| 9 | =head1 Usage | ||
| 10 | |||
| 11 | use Cloner; | ||
| 12 | use Point; | ||
| 13 | |||
| 14 | my $cloner = (Cloner)method : object ($object : object) { | ||
| 15 | my $point = (Point)$object; | ||
| 16 | |||
| 17 | my $cloned_point = Point->new($point->x, $point->y); | ||
| 18 | |||
| 19 | return $cloned_point; | ||
| 20 | }; | ||
| 21 | |||
| 22 | my $point = Point->new(1, 2); | ||
| 23 | my $cloned_point = $cloner->($point); | ||
| 24 | |||
| 25 | =head1 Description | ||
| 26 | |||
| 27 | L<Cloner|SPVM::Cloner> is the interface type for the callback to clone an object. | ||
| 28 | |||
| 29 | =head1 Interface Methodss | ||
| 30 | |||
| 31 | C<required method : object ($object : object);> | ||
| 32 | |||
| 33 | The implementation must receive an object and return the cloned object. | ||
| 34 | |||
| 35 | =head1 Class Methods | ||
| 36 | |||
| 37 | C<static method default_cloner : L<Cloner|SPVM::Cloner> ();> | ||
| 38 | |||
| 39 | Returns a default cloner. | ||
| 40 | |||
| 41 | The implementation of the default cloner is | ||
| 42 | |||
| 43 | method : object ($object : Cloneable) { | ||
| 44 | |||
| 45 | my $clone = (object)undef; | ||
| 46 | |||
| 47 | if ($object) { | ||
| 48 | $clone = $object->clone; | ||
| 49 | } | ||
| 50 | |||
| 51 | return $clone; | ||
| 52 | }; | ||
| 53 | |||
| 54 | If the object $object is undef, returns undef, ohterwise calls L<Cloneable#clone|SPVM::Cloneable/"clone"> method and its return value. | ||
| 55 | |||
| 56 | =head1 Copyright & License | ||
| 57 | |||
| 58 | Copyright (c) 2023 Yuki Kimoto | ||
| 59 | |||
| 60 | MIT License |