File Coverage

blib/lib/MooseX/Clone/Meta/Attribute/Trait/NoClone.pm
Criterion Covered Total %
statement 10 10 100.0
branch 1 2 50.0
condition n/a
subroutine 4 4 100.0
pod 1 1 100.0
total 16 17 94.1


line stmt bran cond sub pod time code
1             package MooseX::Clone::Meta::Attribute::Trait::NoClone;
2             # ABSTRACT: A trait for attributes that should not be copied while cloning
3              
4             our $VERSION = '0.06';
5              
6 2     2   12 use Moose::Role;
  2         3  
  2         19  
7 2     2   11500 use namespace::autoclean;
  2         6  
  2         23  
8              
9             with qw(MooseX::Clone::Meta::Attribute::Trait::Clone::Base);
10              
11 1     1   8660 sub Moose::Meta::Attribute::Custom::Trait::NoClone::register_implementation { __PACKAGE__ }
12              
13             sub clone_value {
14 5     5 1 14 my ( $self, $target, $proto, %args ) = @_;
15              
16             # FIXME default cloning behavior works like this
17             #if ( exists $args{init_arg} ) {
18             # $self->set_value($args{init_arg});
19             #} else {
20             # but i think this is more correct
21              
22 5         21 $self->clear_value($target);
23             $self->initialize_instance_slot(
24             $self->meta->get_meta_instance,
25             $target,
26 5 50       118 { exists $args{init_arg} ? ( $self->init_arg => $args{init_arg} ) : () },
27             );
28             }
29              
30             __PACKAGE__
31              
32             __END__
33              
34             =pod
35              
36             =encoding UTF-8
37              
38             =head1 NAME
39              
40             MooseX::Clone::Meta::Attribute::Trait::NoClone - A trait for attributes that should not be copied while cloning
41              
42             =head1 VERSION
43              
44             version 0.06
45              
46             =head1 SYNOPSIS
47              
48             with qw(MooseX::Clone);
49              
50             has _some_special_thingy => (
51             traits => [qw(NoClone)],
52             );
53              
54             =head1 DESCRIPTION
55              
56             Sometimes certain values should not be carried over when cloning an object.
57              
58             This attribute trait implements just that.
59              
60             =head1 METHODS
61              
62             =over 4
63              
64             =item clone_value
65              
66             If the C<init_arg> param is set (that means an explicit value was given to
67             C<clone>) sets the attribute to that value.
68              
69             Otherwise calls C<clear_value> and C<initialize_instance_slot>.
70              
71             =back
72              
73             =head1 AUTHOR
74              
75             יובל קוג'מן (Yuval Kogman) <nothingmuch@woobling.org>
76              
77             =head1 COPYRIGHT AND LICENSE
78              
79             This software is copyright (c) 2008 by יובל קוג'מן (Yuval Kogman).
80              
81             This is free software; you can redistribute it and/or modify it under
82             the same terms as the Perl 5 programming language system itself.
83              
84             =cut