Mercurial > pub > Impl
comparison lib/IMPL/declare.pm @ 417:3ed0c58e9da3 ref20150831
working on di container, tests
author | cin |
---|---|
date | Mon, 02 Nov 2015 01:56:53 +0300 |
parents | ee36115f6a34 |
children | b0481c071bea |
comparison
equal
deleted
inserted
replaced
416:cc2cf8c0edc2 | 417:3ed0c58e9da3 |
---|---|
1 package IMPL::declare; | 1 package IMPL::declare; |
2 use strict; | 2 use strict; |
3 | 3 |
4 use Carp qw(carp); | 4 use Carp qw(carp); |
5 use IMPL::lang qw( :base ); | |
5 use IMPL::Class::PropertyInfo(); | 6 use IMPL::Class::PropertyInfo(); |
6 use IMPL::Const qw(:access); | 7 use IMPL::Const qw(:access); |
7 use IMPL::require(); | 8 use IMPL::require(); |
8 | 9 |
9 BEGIN { | 10 BEGIN { |
14 sub import { | 15 sub import { |
15 my ( $self, $args ) = @_; | 16 my ( $self, $args ) = @_; |
16 | 17 |
17 return unless $args; | 18 return unless $args; |
18 | 19 |
19 die "A hash reference is required" unless ref $args eq 'HASH'; | 20 die "A hash reference is required" unless ishash($args); |
20 | 21 |
21 no strict 'refs'; | 22 no strict 'refs'; |
22 no warnings 'once'; | 23 no warnings 'once'; |
23 | 24 |
24 my $caller = caller; | 25 my $caller = caller; |
47 my $base = $args->{base} || {}; | 48 my $base = $args->{base} || {}; |
48 | 49 |
49 my %ctor; | 50 my %ctor; |
50 my @isa; | 51 my @isa; |
51 | 52 |
52 if ( ref $base eq 'ARRAY' ) { | 53 if ( isarray($base) ) { |
53 carp "Odd elements number in require" | 54 carp "Odd elements number in require" |
54 unless scalar(@$base) % 2 == 0; | 55 unless scalar(@$base) % 2 == 0; |
55 while ( my ( $class, $mapper ) = splice @$base, 0, 2 ) { | 56 while ( my ( $class, $mapper ) = splice @$base, 0, 2 ) { |
56 _trace("parent $class"); | 57 _trace("parent $class"); |
57 $IMPL::require::level++; | 58 $IMPL::require::level++; |
60 | 61 |
61 push @isa, $class; | 62 push @isa, $class; |
62 $ctor{$class} = $mapper; | 63 $ctor{$class} = $mapper; |
63 } | 64 } |
64 } | 65 } |
65 elsif ( ref $base eq 'HASH' ) { | 66 elsif ( ishash($base) ) { |
66 while ( my ( $class, $mapper ) = each %$base ) { | 67 while ( my ( $class, $mapper ) = each %$base ) { |
67 _trace("parent $class"); | 68 _trace("parent $class"); |
68 $IMPL::require::level++; | 69 $IMPL::require::level++; |
69 $class = $aliases->{$class} || _require($class); | 70 $class = $aliases->{$class} || _require($class); |
70 $IMPL::require::level--; | 71 $IMPL::require::level--; |
75 } | 76 } |
76 | 77 |
77 %{"${caller}::CTOR"} = %ctor; | 78 %{"${caller}::CTOR"} = %ctor; |
78 push @{"${caller}::ISA"}, @isa; | 79 push @{"${caller}::ISA"}, @isa; |
79 | 80 |
80 if ( ref( $args->{meta} ) eq 'ARRAY' ) { | 81 if ( isarray( $args->{meta} ) ) { |
81 $caller->SetMeta($_) foreach @{ $args->{meta} }; | 82 $caller->SetMeta($_) foreach @{ $args->{meta} }; |
82 } | 83 } |
83 | 84 |
84 my $props = $args->{props} || []; | 85 my $props = $args->{props} || []; |
85 | 86 |
86 if ( $props eq 'HASH' ) { | 87 if ( ishash($props) ) { |
87 $props = [%$props]; | 88 $props = [%$props]; |
88 } | 89 } |
89 | 90 |
90 die "A hash or an array reference is required in the properties list" | 91 die "A hash or an array reference is required in the properties list" |
91 unless ref $props eq 'ARRAY'; | 92 unless isarray($props); |
92 | 93 |
93 carp "Odd elements number in properties declaration of $caller" | 94 carp "Odd elements number in properties declaration of $caller" |
94 unless scalar(@$props) % 2 == 0; | 95 unless scalar(@$props) % 2 == 0; |
95 | 96 |
96 if (@$props) { | 97 if (@$props) { |