| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | package MooX::Role::Reconstruct; | 
| 2 |  |  |  |  |  |  |  | 
| 3 | 11 |  |  | 11 |  | 108814 | use strict; | 
|  | 11 |  |  |  |  | 16 |  | 
|  | 11 |  |  |  |  | 413 |  | 
| 4 | 11 |  |  | 11 |  | 112 | use warnings FATAL => 'all'; | 
|  | 11 |  |  |  |  | 15 |  | 
|  | 11 |  |  |  |  | 366 |  | 
| 5 |  |  |  |  |  |  |  | 
| 6 | 11 |  |  | 11 |  | 226 | use 5.006; | 
|  | 11 |  |  |  |  | 25 |  | 
|  | 11 |  |  |  |  | 475 |  | 
| 7 |  |  |  |  |  |  |  | 
| 8 |  |  |  |  |  |  | our $VERSION = 'v0.1.2'; | 
| 9 |  |  |  |  |  |  |  | 
| 10 | 11 |  |  | 11 |  | 4632 | use Sub::Quote; | 
|  | 11 |  |  |  |  | 27451 |  | 
|  | 11 |  |  |  |  | 591 |  | 
| 11 | 11 |  |  | 11 |  | 51 | use Sub::Defer; | 
|  | 11 |  |  |  |  | 13 |  | 
|  | 11 |  |  |  |  | 403 |  | 
| 12 | 11 |  |  | 11 |  | 43 | use Role::Tiny; | 
|  | 11 |  |  |  |  | 12 |  | 
|  | 11 |  |  |  |  | 63 |  | 
| 13 |  |  |  |  |  |  |  | 
| 14 |  |  |  |  |  |  | sub import { | 
| 15 | 10 |  |  | 10 |  | 112214 | my $target = shift; | 
| 16 | 10 | 50 |  |  |  | 61 | my %args = @_ ? (@_) : ( method => 'reconstruct' ); | 
| 17 |  |  |  |  |  |  |  | 
| 18 | 10 |  |  |  |  | 28 | my $method = delete( $args{method} ); | 
| 19 |  |  |  |  |  |  |  | 
| 20 | 10 | 50 | 33 |  |  | 98 | die 'MooX::Role::Reconstruct can only be used on Moo classes.' | 
| 21 |  |  |  |  |  |  | unless $Moo::MAKERS{$target} && $Moo::MAKERS{$target}{is_class}; | 
| 22 |  |  |  |  |  |  |  | 
| 23 | 10 |  |  |  |  | 42 | my $con = Moo->_constructor_maker_for($target); | 
| 24 |  |  |  |  |  |  |  | 
| 25 |  |  |  |  |  |  | defer_sub( | 
| 26 |  |  |  |  |  |  | "${target}::${method}" => sub { | 
| 27 |  |  |  |  |  |  |  | 
| 28 |  |  |  |  |  |  | # don't alter the original specs if called before new | 
| 29 | 10 |  |  | 10 |  | 20795 | my %spec; | 
| 30 | 10 |  |  |  |  | 21 | for ( keys( %{ $con->{attribute_specs} } ) ) { | 
|  | 10 |  |  |  |  | 76 |  | 
| 31 | 22 |  |  |  |  | 28 | $spec{$_} = { %{ $con->{attribute_specs}{$_} } }; | 
|  | 22 |  |  |  |  | 115 |  | 
| 32 |  |  |  |  |  |  | } | 
| 33 | 10 |  |  |  |  | 60 | for ( grep exists( $spec{$_}{init_arg} ), keys(%spec) ) | 
| 34 |  |  |  |  |  |  | { | 
| 35 | 19 | 100 |  |  |  | 76 | delete($spec{$_}{init_arg}) unless $spec{$_}{keep_init}; | 
| 36 |  |  |  |  |  |  | } | 
| 37 | 10 |  |  |  |  | 78 | unquote_sub $con->generate_method( | 
| 38 |  |  |  |  |  |  | $target, $method, \%spec, { no_install => 1 } | 
| 39 |  |  |  |  |  |  | ); | 
| 40 |  |  |  |  |  |  | } | 
| 41 | 10 |  |  |  |  | 123 | ); | 
| 42 |  |  |  |  |  |  |  | 
| 43 | 10 |  |  |  |  | 346 | return; | 
| 44 |  |  |  |  |  |  | } | 
| 45 |  |  |  |  |  |  |  | 
| 46 |  |  |  |  |  |  | 1; | 
| 47 |  |  |  |  |  |  |  | 
| 48 |  |  |  |  |  |  | __END__ |