blib/lib/Gapp/Moose/Meta/Attribute/Trait/GappWidget.pm untested

filter: Statementstmt 0.0% 0 / 36 Branchbran 0.0% 0 / 20 Conditioncond 0.0% 0 / 9 MC/DCmcdc 0.0% 0 / 5 Subroutinesub 0.0% 0 / 3 Podpod 0.0% 0 / 1 totaltotal 0.0% 0 / 74 CC 1 SCAR 6.9
CC
1
Cov
0%
register_implementation
2.0
BEGIN
2.0
BEGIN
2.0
CRAP 2.0
1 package Gapp::Moose::Meta::Attribute::Trait::GappWidget;
2 {
3 $Gapp::Moose::Meta::Attribute::Trait::GappWidget::VERSION = '0.60';
4 }
5 use Moose::Role;
6  
7 use MooseX::Types::Moose qw( ArrayRef CodeRef HashRef Int Str Undef );
8  
9 has 'gclass' => (
10 is => 'rw',
11 isa => 'Str',
12 );
13  
14 has 'construct' => (
15 is => 'rw',
16 isa => 'ArrayRef|CodeRef|Int|Undef',
17 );
18  
19 has 'constructor' => (
20 is => 'rw',
21 isa => 'Str',
22 default => 'new',
23 );
24  
25 before '_process_options' => sub {
26 my ( $class, $name, $opts ) = @_;
27
28 if ( $opts->{construct} ) {
29 warn 'you provided a construct argument and a default' if $opts->{default};
30 warn 'you provided a construct argument and a builder' if $opts->{builder};
31
32 $opts->{default} = sub {
33 my ( $self ) = @_;
34 my $att = $self->meta->find_attribute_by_name( $name );
35
36 my $wclass = $att->gclass;
37 my $wmethod = $att->constructor;
38
39 if ( ! $wclass ) {
40 confess "Could not consruct widget '$name', you did not supply a widget class";
41 }
42
43 my %opts;
44 for ( $att->construct ) {
45 last if is_Int( $_ ) && $_;
46 %opts = %$_ and last if is_HashRef( $_ );
47 %opts = ( @$_ ) and last if is_ArrayRef( $_ );
48 %opts = $_->( $self ) and last if is_CodeRef( $_ );
49 }
50
51 my $w = $wclass->$wmethod( %opts );
52
53 return $w;
54 };
55 }
56 $opts->{is} = 'ro' if ! exists $opts->{is};
57 $opts->{lazy} = 1 if ! exists $opts->{lazy};
58
59 };
60  
61 package Moose::Meta::Attribute::Custom::Trait::GappWidget;
62 {
63 $Moose::Meta::Attribute::Custom::Trait::GappWidget::VERSION = '0.60';
64 }
65 sub register_implementation { 'Gapp::Moose::Meta::Attribute::Trait::GappWidget' };
66  
67 1;