annotate Lib/IMPL/lang.pm @ 167:1f7a6d762394

SQL schema in progress
author sourcer
date Thu, 12 May 2011 08:57:19 +0400
parents 76515373dac0
children 6148f89bb7bf
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
164
eb3e9861a761 SQL traits in progress
wizard
parents:
diff changeset
1 package IMPL::lang;
eb3e9861a761 SQL traits in progress
wizard
parents:
diff changeset
2 use strict;
eb3e9861a761 SQL traits in progress
wizard
parents:
diff changeset
3 use warnings;
eb3e9861a761 SQL traits in progress
wizard
parents:
diff changeset
4
165
76515373dac0 Added Class::Template,
wizard
parents: 164
diff changeset
5 use parent qw(Exporter);
164
eb3e9861a761 SQL traits in progress
wizard
parents:
diff changeset
6 use IMPL::_core::version;
eb3e9861a761 SQL traits in progress
wizard
parents:
diff changeset
7
167
1f7a6d762394 SQL schema in progress
sourcer
parents: 165
diff changeset
8 require IMPL::Class::PropertyInfo;
164
eb3e9861a761 SQL traits in progress
wizard
parents:
diff changeset
9
167
1f7a6d762394 SQL schema in progress
sourcer
parents: 165
diff changeset
10 our @EXPORT = qw(&is);
1f7a6d762394 SQL schema in progress
sourcer
parents: 165
diff changeset
11 our %EXPORT_TAGS = (
1f7a6d762394 SQL schema in progress
sourcer
parents: 165
diff changeset
12 base => [
1f7a6d762394 SQL schema in progress
sourcer
parents: 165
diff changeset
13 qw(
1f7a6d762394 SQL schema in progress
sourcer
parents: 165
diff changeset
14 &is
1f7a6d762394 SQL schema in progress
sourcer
parents: 165
diff changeset
15 )
1f7a6d762394 SQL schema in progress
sourcer
parents: 165
diff changeset
16 ],
1f7a6d762394 SQL schema in progress
sourcer
parents: 165
diff changeset
17 constants => [
1f7a6d762394 SQL schema in progress
sourcer
parents: 165
diff changeset
18 qw(
1f7a6d762394 SQL schema in progress
sourcer
parents: 165
diff changeset
19 &ACCESS_PUBLIC
1f7a6d762394 SQL schema in progress
sourcer
parents: 165
diff changeset
20 &ACCESS_PROTECTED
1f7a6d762394 SQL schema in progress
sourcer
parents: 165
diff changeset
21 &ACCESS_PRIVATE
1f7a6d762394 SQL schema in progress
sourcer
parents: 165
diff changeset
22 &PROP_GET
1f7a6d762394 SQL schema in progress
sourcer
parents: 165
diff changeset
23 &PROP_SET
1f7a6d762394 SQL schema in progress
sourcer
parents: 165
diff changeset
24 &PROP_OWNERSET
1f7a6d762394 SQL schema in progress
sourcer
parents: 165
diff changeset
25 &PROP_LIST
1f7a6d762394 SQL schema in progress
sourcer
parents: 165
diff changeset
26 &PROP_ALL
1f7a6d762394 SQL schema in progress
sourcer
parents: 165
diff changeset
27 )
1f7a6d762394 SQL schema in progress
sourcer
parents: 165
diff changeset
28 ],
1f7a6d762394 SQL schema in progress
sourcer
parents: 165
diff changeset
29
1f7a6d762394 SQL schema in progress
sourcer
parents: 165
diff changeset
30 declare => [
1f7a6d762394 SQL schema in progress
sourcer
parents: 165
diff changeset
31 qw(
1f7a6d762394 SQL schema in progress
sourcer
parents: 165
diff changeset
32 &public
1f7a6d762394 SQL schema in progress
sourcer
parents: 165
diff changeset
33 &protected
1f7a6d762394 SQL schema in progress
sourcer
parents: 165
diff changeset
34 &private
1f7a6d762394 SQL schema in progress
sourcer
parents: 165
diff changeset
35 &virtual
1f7a6d762394 SQL schema in progress
sourcer
parents: 165
diff changeset
36 &property
1f7a6d762394 SQL schema in progress
sourcer
parents: 165
diff changeset
37 &static
1f7a6d762394 SQL schema in progress
sourcer
parents: 165
diff changeset
38 &property
1f7a6d762394 SQL schema in progress
sourcer
parents: 165
diff changeset
39 )
1f7a6d762394 SQL schema in progress
sourcer
parents: 165
diff changeset
40 ],
1f7a6d762394 SQL schema in progress
sourcer
parents: 165
diff changeset
41 compare => [
1f7a6d762394 SQL schema in progress
sourcer
parents: 165
diff changeset
42 qw(
1f7a6d762394 SQL schema in progress
sourcer
parents: 165
diff changeset
43 &equals
1f7a6d762394 SQL schema in progress
sourcer
parents: 165
diff changeset
44 &equals_s
1f7a6d762394 SQL schema in progress
sourcer
parents: 165
diff changeset
45 )
1f7a6d762394 SQL schema in progress
sourcer
parents: 165
diff changeset
46 ]
1f7a6d762394 SQL schema in progress
sourcer
parents: 165
diff changeset
47 );
1f7a6d762394 SQL schema in progress
sourcer
parents: 165
diff changeset
48
1f7a6d762394 SQL schema in progress
sourcer
parents: 165
diff changeset
49 our @EXPORT_OK = keys %{ { map (($_,1) , map (@{$_}, values %EXPORT_TAGS) ) } };
1f7a6d762394 SQL schema in progress
sourcer
parents: 165
diff changeset
50
1f7a6d762394 SQL schema in progress
sourcer
parents: 165
diff changeset
51 use constant {
1f7a6d762394 SQL schema in progress
sourcer
parents: 165
diff changeset
52 ACCESS_PUBLIC => 1,
1f7a6d762394 SQL schema in progress
sourcer
parents: 165
diff changeset
53 ACCESS_PROTECTED => 2,
1f7a6d762394 SQL schema in progress
sourcer
parents: 165
diff changeset
54 ACCESS_PRIVATE => 3,
1f7a6d762394 SQL schema in progress
sourcer
parents: 165
diff changeset
55 PROP_GET => 1,
1f7a6d762394 SQL schema in progress
sourcer
parents: 165
diff changeset
56 PROP_SET => 2,
1f7a6d762394 SQL schema in progress
sourcer
parents: 165
diff changeset
57 PROP_OWNERSET => 10,
1f7a6d762394 SQL schema in progress
sourcer
parents: 165
diff changeset
58 PROP_LIST => 4,
1f7a6d762394 SQL schema in progress
sourcer
parents: 165
diff changeset
59 PROP_ALL => 3
1f7a6d762394 SQL schema in progress
sourcer
parents: 165
diff changeset
60 };
164
eb3e9861a761 SQL traits in progress
wizard
parents:
diff changeset
61
eb3e9861a761 SQL traits in progress
wizard
parents:
diff changeset
62 sub is($$) {
167
1f7a6d762394 SQL schema in progress
sourcer
parents: 165
diff changeset
63 eval { $_[0]->isa( $_[1] ) };
1f7a6d762394 SQL schema in progress
sourcer
parents: 165
diff changeset
64 }
1f7a6d762394 SQL schema in progress
sourcer
parents: 165
diff changeset
65
1f7a6d762394 SQL schema in progress
sourcer
parents: 165
diff changeset
66 sub virtual($) {
1f7a6d762394 SQL schema in progress
sourcer
parents: 165
diff changeset
67 $_[0]->Virtual(1);
1f7a6d762394 SQL schema in progress
sourcer
parents: 165
diff changeset
68 $_[0];
1f7a6d762394 SQL schema in progress
sourcer
parents: 165
diff changeset
69 }
1f7a6d762394 SQL schema in progress
sourcer
parents: 165
diff changeset
70
1f7a6d762394 SQL schema in progress
sourcer
parents: 165
diff changeset
71 sub public($) {
1f7a6d762394 SQL schema in progress
sourcer
parents: 165
diff changeset
72 $_[0]->Access(ACCESS_PUBLIC);
1f7a6d762394 SQL schema in progress
sourcer
parents: 165
diff changeset
73 $_[0]->Implement;
1f7a6d762394 SQL schema in progress
sourcer
parents: 165
diff changeset
74 $_[0];
1f7a6d762394 SQL schema in progress
sourcer
parents: 165
diff changeset
75 }
1f7a6d762394 SQL schema in progress
sourcer
parents: 165
diff changeset
76
1f7a6d762394 SQL schema in progress
sourcer
parents: 165
diff changeset
77 sub private($) {
1f7a6d762394 SQL schema in progress
sourcer
parents: 165
diff changeset
78 $_[0]->Access(ACCESS_PRIVATE);
1f7a6d762394 SQL schema in progress
sourcer
parents: 165
diff changeset
79 $_[0]->Implement;
1f7a6d762394 SQL schema in progress
sourcer
parents: 165
diff changeset
80 $_[0];
1f7a6d762394 SQL schema in progress
sourcer
parents: 165
diff changeset
81 }
1f7a6d762394 SQL schema in progress
sourcer
parents: 165
diff changeset
82
1f7a6d762394 SQL schema in progress
sourcer
parents: 165
diff changeset
83 sub protected($) {
1f7a6d762394 SQL schema in progress
sourcer
parents: 165
diff changeset
84 $_[0]->Access(ACCESS_PROTECTED);
1f7a6d762394 SQL schema in progress
sourcer
parents: 165
diff changeset
85 $_[0]->Implement;
1f7a6d762394 SQL schema in progress
sourcer
parents: 165
diff changeset
86 $_[0];
164
eb3e9861a761 SQL traits in progress
wizard
parents:
diff changeset
87 }
eb3e9861a761 SQL traits in progress
wizard
parents:
diff changeset
88
167
1f7a6d762394 SQL schema in progress
sourcer
parents: 165
diff changeset
89 sub property($$;$) {
1f7a6d762394 SQL schema in progress
sourcer
parents: 165
diff changeset
90 my ( $propName, $mutators, $attributes ) = @_;
1f7a6d762394 SQL schema in progress
sourcer
parents: 165
diff changeset
91 my $Info = new IMPL::Class::PropertyInfo(
1f7a6d762394 SQL schema in progress
sourcer
parents: 165
diff changeset
92 {
1f7a6d762394 SQL schema in progress
sourcer
parents: 165
diff changeset
93 Name => $propName,
1f7a6d762394 SQL schema in progress
sourcer
parents: 165
diff changeset
94 Mutators => $mutators,
1f7a6d762394 SQL schema in progress
sourcer
parents: 165
diff changeset
95 Class => scalar(caller),
1f7a6d762394 SQL schema in progress
sourcer
parents: 165
diff changeset
96 Attributes => $attributes
1f7a6d762394 SQL schema in progress
sourcer
parents: 165
diff changeset
97 }
1f7a6d762394 SQL schema in progress
sourcer
parents: 165
diff changeset
98 );
1f7a6d762394 SQL schema in progress
sourcer
parents: 165
diff changeset
99 return $Info;
1f7a6d762394 SQL schema in progress
sourcer
parents: 165
diff changeset
100 }
1f7a6d762394 SQL schema in progress
sourcer
parents: 165
diff changeset
101
1f7a6d762394 SQL schema in progress
sourcer
parents: 165
diff changeset
102 sub static($$) {
1f7a6d762394 SQL schema in progress
sourcer
parents: 165
diff changeset
103 my ( $name, $value ) = @_;
1f7a6d762394 SQL schema in progress
sourcer
parents: 165
diff changeset
104 my $class = caller;
1f7a6d762394 SQL schema in progress
sourcer
parents: 165
diff changeset
105 $class->static_accessor( $name, $value );
1f7a6d762394 SQL schema in progress
sourcer
parents: 165
diff changeset
106 }
1f7a6d762394 SQL schema in progress
sourcer
parents: 165
diff changeset
107
1f7a6d762394 SQL schema in progress
sourcer
parents: 165
diff changeset
108 sub equals {
1f7a6d762394 SQL schema in progress
sourcer
parents: 165
diff changeset
109 if (defined $_[0]) {
1f7a6d762394 SQL schema in progress
sourcer
parents: 165
diff changeset
110 return 0 if (not defined $_[1]);
1f7a6d762394 SQL schema in progress
sourcer
parents: 165
diff changeset
111
1f7a6d762394 SQL schema in progress
sourcer
parents: 165
diff changeset
112 return $_[0] == $_[1];
1f7a6d762394 SQL schema in progress
sourcer
parents: 165
diff changeset
113 } else {
1f7a6d762394 SQL schema in progress
sourcer
parents: 165
diff changeset
114 return 0 if defined $_[1];
1f7a6d762394 SQL schema in progress
sourcer
parents: 165
diff changeset
115
1f7a6d762394 SQL schema in progress
sourcer
parents: 165
diff changeset
116 return 1;
1f7a6d762394 SQL schema in progress
sourcer
parents: 165
diff changeset
117 }
1f7a6d762394 SQL schema in progress
sourcer
parents: 165
diff changeset
118 }
1f7a6d762394 SQL schema in progress
sourcer
parents: 165
diff changeset
119
1f7a6d762394 SQL schema in progress
sourcer
parents: 165
diff changeset
120 sub equals_s {
1f7a6d762394 SQL schema in progress
sourcer
parents: 165
diff changeset
121 if (defined $_[0]) {
1f7a6d762394 SQL schema in progress
sourcer
parents: 165
diff changeset
122 return 0 if (not defined $_[1]);
1f7a6d762394 SQL schema in progress
sourcer
parents: 165
diff changeset
123
1f7a6d762394 SQL schema in progress
sourcer
parents: 165
diff changeset
124 return $_[0] eq $_[1];
1f7a6d762394 SQL schema in progress
sourcer
parents: 165
diff changeset
125 } else {
1f7a6d762394 SQL schema in progress
sourcer
parents: 165
diff changeset
126 return 0 if defined $_[1];
1f7a6d762394 SQL schema in progress
sourcer
parents: 165
diff changeset
127
1f7a6d762394 SQL schema in progress
sourcer
parents: 165
diff changeset
128 return 1;
1f7a6d762394 SQL schema in progress
sourcer
parents: 165
diff changeset
129 }
1f7a6d762394 SQL schema in progress
sourcer
parents: 165
diff changeset
130 }
1f7a6d762394 SQL schema in progress
sourcer
parents: 165
diff changeset
131
1f7a6d762394 SQL schema in progress
sourcer
parents: 165
diff changeset
132 1;