IntrospectionMethods/Catalog.pm

filter: Statementstmt 91.4% 193 / 211 Branchbran 70.3% 45 / 64 Conditioncond 71.4% 5 / 7 MC/DCmcdc 25.0% 1 / 4 Subroutinesub 92.5% 37 / 40 Podpod 40.0% 2 / 5 totaltotal 85.5% 283 / 331 CC 42 SCAR 14.0
CC
42
Cov
86%
slot
12.6
change
6.3
rebuild
6.0
CRAP 4.0
« IntrospectionMethods.pm ↑ Summary IntrospectionMethods/Parent.pm »
1 # $Author: domi $
2 # $Date: 2004/12/13 12:20:10 $
3 # $Name: $
4 # $Revision: 1.4 $
5  
6 package Class::IntrospectionMethods::Catalog ;
7 16 ▶use strict ;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 16 ▶use warnings ;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 16 ▶use Carp ;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 16 ▶use Storable qw/dclone/;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 16 ▶use Data::Dumper ;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 16 require Exporter;
14 16 ▶use vars qw/$VERSION @ISA @EXPORT_OK @CARP_NOT/ ;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 16 @ISA = qw(Exporter);
16 16 @EXPORT_OK = qw(set_global_catalog set_method_info set_method_in_catalog);
17 16 @CARP_NOT=qw/Class::IntrospectionMethods/ ;
18  
19 16 $VERSION = sprintf "%d.%03d", q$Revision: 1.4 $ =~ /(\d+)\.(\d+)/;
20  
21 16 my $obsolete_behavior = 'carp' ;
22 16 my $support_legacy = 0 ;
23  
24 sub set_obsolete_behavior
25 15 ▶ {
Subroutine set_obsolete_behavior: called CC=1 SCAR=0.0
Pod undocumented
26 15 $obsolete_behavior = shift;
27 15 $support_legacy = shift ;
28 }
29  
30 sub warn_obsolete
31 1 ▶ {
Subroutine warn_obsolete: called CC=2 SCAR=7.4
Pod undocumented
32 1 ▶ return if $obsolete_behavior eq 'skip' ;
Branch: 1 branch
BranchTrueFalseTotal
if $obsolete_behavior eq "skip" 1 0 1
33 16 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
34 0 $obsolete_behavior->(@_) ;
35 }
36  
37 =head1 NAME
38  
39 Class::IntrospectionMethods::Catalog - manage catalogs from IntrospectionMethods
40  
41 =head1 SYNOPSIS
42  
43 No synopsis. Directly used by Class::IntrospectionMethods
44  
45 =head1 DESCRIPTION
46  
47 This class handles slot catalogs for L<Class::IntrospectionMethods>.
48  
49 =cut
50  
51 # These lexical variables are also used in ClassCatalog and
52 # ObjectCatalog
53 16 my %construction_info ;
54 my %catalog_info ;
55  
56 =head1 Exported functions
57  
58 =head2 set_method_info( target_class, method_name, info_ref )
59  
60 Store construction info for method C<method_name> of class
61 C<target_class>.
62  
63 =cut
64  
65 sub set_method_info
66 91 ▶ {
Subroutine set_method_info: called CC=1 SCAR=0.0
Pod documented
67 91 my ($target_class, $maker_slot_name, $info) = @_ ;
68 91 $construction_info{$target_class}{$maker_slot_name} = $info ;
69 }
70  
71 =head2 set_global_catalog (target_class, ...)
72  
73 Store catalog informations. The first parameter is the class featuring
74 the methods declared in the global catalog.
75  
76 Following paramaters is a set of named paramaters (e.g. key => value):
77  
78 =over
79  
80 =item name
81  
82 Mandatory name for the global catalog
83  
84 =item list
85  
86 array ref containing the list of slot and catalog. E.g.:
87  
88 list => [
89 [qw/foo bar baz/] => foo_catalog,
90 [qw/a b z/] => alpha_catalog,
91 my_object => my_catalog
92 ],
93  
94 =item isa
95  
96 Optional hash ref declaring a containment for catalog. E.g:
97  
98 list => [ 'foo' => 'USER' ,
99 'admin' => 'ROOT' ],
100 isa => { USER => 'ROOT' }
101  
102 Then the 'ROOT' catalog will return 'foo', and the 'USER' catalog will
103 return 'foo' and 'admin'.
104  
105 =item help
106  
107 Optional hash ref (C<< slot_name => help >>). Store some help
108 information for each slot.
109  
110 =back
111  
112 set_global_catalog will construct:
113  
114 =over
115  
116 =item *
117  
118 A ClassCatalog object containing the global catalog informations.
119  
120 =item *
121  
122 A sub_ref containing the ClassCatalog object in a closure.
123  
124 =back
125  
126 Returns ( C<slot_name>, sub_ref ). The sub_ref is to be installed in
127 the target class.
128  
129 When called as a class method, the subref will return the ClassCatalog
130 object. When called as a target class method, the subref will return
131 an ObjectCatalog object associated to the ClassCatalog object stored
132 in the closure.
133  
134 These 2 object have the same API. ObjectCatalog is used to contain
135 catalog changes that may occur at run-time. ClassCatalog informations
136 will not change.
137  
138 =cut
139  
140 # the closures defined here have a class scope not an object
141 # scope. I.e there's one storage per class
142  
143 sub set_global_catalog
144 6 ▶ {
Subroutine set_global_catalog: called CC=3 SCAR=11.1
Pod documented
145 6 my $target_class = shift ;
146 6 my %arg = @_ ;
147  
148 my $global_catalog_name = delete $arg{name}
149 6 ▶ or croak "set_global_catalog: no name defined";
Branch: 1 branch
BranchTrueFalseTotal
my $global_catalog_name = delete $arg{"name"} or croak("set_global_catalog: no name defined") 6 0 6
150  
151 # get list of slot -> catalog
152 6 ▶ croak "set_global_catalog: no list defined" unless defined $arg{list};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $arg{"list"} 0 6 6
153  
154 # this object is stored in the closure below
155 6 my $class_catalog = Class::IntrospectionMethods::ClassCatalog
156 -> new ( target_class => $target_class, %arg ) ;
157  
158 my $sub = sub
159 45 ▶ {
Subroutine __ANON__: called CC=3 SCAR=11.0
160 45 my $self = shift ;
161 45 ▶ return $self->{$global_catalog_name} ||=
Branch: 1 branch
BranchTrueFalseTotal
if ref $self 18 27 45
Condition66%2/3
$self->{$global_catalog_name} ||= "Class::IntrospectionMethods::ObjectCatalog"->new("class_catalog", $class_catalog)
l!l&&r!l&&!r
1440
MC/DC0%0/2
$self->{$global_catalog_name} ||= "Class::IntrospectionMethods::ObjectCatalog"->new("class_catalog", $class_catalog)
$self->{$global_catalog_name} "Class::IntrospectionMethods::ObjectCatalog"->new("class_catalog", $class_catalog)
Truth table66%2/3
A ||= B
A= $self->{$global_catalog_name}B= "Class::IntrospectionMethods::ObjectCatalog"->new("class_catalog", $class_catalog)
ABresult
1X1
011
000
162 Class::IntrospectionMethods::ObjectCatalog ->
163 new ( class_catalog => $class_catalog ) if ref $self;
164 27 return $class_catalog ;
165 6 } ;
166  
167 6 $catalog_info{$target_class}=$sub ;
168  
169 6 my @methods = ($global_catalog_name, $sub ) ;
170  
171 6 return @methods ;
172 }
173  
174 sub set_method_in_catalog
175 17 ▶ {
Subroutine set_method_in_catalog: called CC=2 SCAR=7.0
Pod undocumented
176 17 my ($target_class,$slot,$catalog) = @_ ;
177  
178 croak "set_global_catalog was not called for class $target_class, ",
179 "Did you forgot to 'global_catalog' parameter in make_methods call ?"
180 17 ▶ unless defined $catalog_info{$target_class} ;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $catalog_info{$target_class} 0 17 17
181  
182 17 my $f = $catalog_info{$target_class} ;
183  
184 17 &$f->add($slot,$catalog) ;
185 }
186  
187 16 1;
188  
189 package Class::IntrospectionMethods::AnyCatalog ;
190 16 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
191  
192 # data : { catalog_list => { catalog_a => [slot1 slot2],
193 # catalog_b => [slot2 slot3]},
194 # slot_list => { slot1 => [catalog_a],
195 # slot2 => [catalog_a catalog_b],
196 # slot3 => [catalog_b]} },
197 # ordered_slot_list => [ slot1 slot2 slot3 ]
198  
199 0 ▶sub all {confess "deprecated"}
Subroutine all: not called CC=1 SCAR=6.9
200  
201 sub rebuild
202 0 ▶ {
Subroutine rebuild: not called CC=2 SCAR=17.9
203 0 my $self = shift ;
204  
205 # reset and rebuild slot list from catalog_list
206 0 delete $self->{slot_list} ;
207 0 foreach my $catalog (sort keys %{$self->{catalog_list}} )
208 {
209 0 map{ push @{$self->{slot_list}{$_}}, $catalog ;}
210 0 @{$self->{catalog_list}{$catalog}} ;
211 }
212 } ;
213  
214 =head1 ClassCatalog or ObjectCatalog methods
215  
216 =cut
217  
218 =head2 catalog( slot_name )
219  
220 Returns the catalogs names containing this slot (does not take into
221 accounts the isa stuff)
222  
223 Return either an array or an array ref depending on context.
224  
225 =cut
226  
227 sub catalog
228 17 ▶ {
Subroutine catalog: called CC=4 SCAR=14.3
229 17 my ($self, $slot_name) = @_ ;
230  
231 17 ▶ croak "catalog: Missing slot name"
Branch: 1 branch
BranchTrueFalseTotal
unless defined $slot_name 0 17 17
232 unless defined $slot_name;
233  
234 # returns the catalogs names containing this slot (does not take
235 # into accounts the isa stuff)
236 17 my $slist = $self->{slot_list} ;
237  
238 croak "catalog: unknown slot $slot_name, expected",
239 join(',',keys %$slist)
240 17 ▶ unless defined $slist->{$slot_name};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $slist->{$slot_name} 0 17 17
241  
242 17 my @result = @{$slist->{$slot_name}} ;
243  
244 17 ▶ return wantarray ? @result : \@result ;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 17 0 17
245 }
246  
247 =head2 slot ( catalog_name, ... )
248  
249 Returns the slots contained in the catalogs passed as
250 arguments. (takes into accounts the isa parameter)
251  
252 =cut
253  
254 sub slot
255 31 ▶ {
Subroutine slot: called CC=11 SCAR=25.3
256 31 my $self = shift ;
257 31 my @all_cats = @_ ;
258  
259 31 ▶ croak "slot: Missing catalog name" unless @_ ;
Branch: 1 branch
BranchTrueFalseTotal
unless @_ 0 31 31
260  
261 31 my $clist = $self->{catalog_list} ;
262  
263 31 foreach my $catalog_name (@all_cats)
264 {
265 32 ▶ if (not defined $clist->{$catalog_name})
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $clist->{$catalog_name}) 0 32 32
266 {
267 0 ▶ if ($support_legacy)
Branch: 1 branch
BranchTrueFalseTotal
if ($support_legacy) { } 0 0 0
268 {
269 0 $self->{catalog_list}{$catalog_name} = [] ;
270 0 $self->{class_catalog}->add_catalog($catalog_name) ;
271 0 Class::IntrospectionMethods::Catalog::warn_obsolete
272 ("Warning: undeclared catalog $catalog_name, Created ...");
273 }
274 else
275 {
276 0 croak "slot: unknown catalog $catalog_name, expected",
277 join(',',keys %$clist) ;
278 }
279 }
280 }
281  
282 # add inherited catalogs
283 push @all_cats,
284 31 map {$self->catalog_isa($_)} @all_cats ;
285  
286 #print "slot: @_ is @all_cats\n";
287 31 my @result ;
288 31 foreach my $slot (@{$self->ordered_slot_list()})
289 {
290 232 my @c = @{$self->{slot_list}{$slot}} ;
291 232 my %c ;
292 232 foreach my $c (@c) {$c{$c} = 1}
293 232 my %isect ;
294 232 ▶ foreach my $c (@all_cats) { $isect{$c} = 1 if $c{$c} }
Branch: 1 branch
BranchTrueFalseTotal
if $c{$c} 119 167 286
295  
296 232 ▶ push @result, $slot if scalar keys %isect ;
Branch: 1 branch
BranchTrueFalseTotal
if scalar keys %isect 117 115 232
297 } ;
298  
299 #print "result is @result\n";
300 31 ▶ return wantarray ? @result : \@result ;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 27 4 31
301 }
302  
303 =head2 all_slot()
304  
305 Return a list of all slots (respecting the order defined in
306 global_catalog).
307  
308 =cut
309  
310 sub all_slot
311 1 ▶ {
Subroutine all_slot: called CC=1 SCAR=0.0
312 1 my $self = shift;
313 1 return @{$self->ordered_slot_list} ;
314 }
315  
316 =head2 all_catalog()
317  
318 Returns a sorted list of all defined catalogs.
319  
320 =cut
321  
322 sub all_catalog
323 8 ▶ {
Subroutine all_catalog: called CC=1 SCAR=0.0
324 8 my ($self) = @_ ;
325 8 return sort keys %{$self->{catalog_list}} ;
326 }
327  
328 #internal
329 sub update_catalog_list
330 15 ▶ {
Subroutine update_catalog_list: called CC=2 SCAR=6.9
331 15 my $self = shift ;
332  
333 # reset and update catalog lists (which is somewhat different from rebuild)
334 15 delete $self->{catalog} ;
335 15 foreach my $slot (sort keys %{$self->{slot_list}} )
336 {
337 89 map{ push @{$self->{catalog_list}{$_}}, $slot ;}
338 78 @{$self->{slot_list}{$slot}} ;
339 }
340 }
341  
342 package Class::IntrospectionMethods::ObjectCatalog ;
343  
344 16 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
345 16 ▶use Storable qw(dclone) ;
Subroutine BEGIN: called CC=1 SCAR=0.0
346 16 ▶use vars qw($AUTOLOAD @ISA);
Subroutine BEGIN: called CC=1 SCAR=0.0
347  
348 16 @ISA = qw/Class::IntrospectionMethods::AnyCatalog/ ;
349  
350 sub new
351 4 ▶ {
Subroutine new: called CC=2 SCAR=7.0
352 4 my $type =shift ;
353 4 my $self = { @_ } ;
354  
355 croak __PACKAGE__,"->new: no class_catalog given" unless defined
356 4 ▶ $self->{class_catalog} ;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"class_catalog"} 0 4 4
357  
358 $self->{slot_list} =
359 4 dclone($self->{class_catalog}->slot_list() ) ;
360  
361 4 bless $self, $type ;
362 4 $self->update_catalog_list ;
363  
364 4 return $self ;
365 }
366  
367 =head1 ObjectClass methods
368  
369 Unknown methods will be forwarded to associated ClassCatalog object.
370  
371 =head2 change( slot_name, catalog_name )
372  
373 Move the slot into catalog C<catalog_name>.
374  
375 =cut
376  
377 sub change
378 4 ▶ {
Subroutine change: called CC=6 SCAR=18.4
379 4 my ($self, $slot_name, $catalog_name) = @_ ;
380  
381 4 ▶ croak "set_catalog, change command: Missing slot name"
Branch: 1 branch
BranchTrueFalseTotal
unless defined $slot_name 0 4 4
382 unless defined $slot_name;
383 4 ▶ croak "set_catalog, change command: Missing catalog name"
Branch: 1 branch
BranchTrueFalseTotal
unless defined $catalog_name 0 4 4
384 unless defined $catalog_name;
385  
386 # check new catalog
387 4 ▶ my @cat = ref $catalog_name ? sort @$catalog_name : ($catalog_name) ;
Branch: 1 branch
BranchTrueFalseTotal
ref $catalog_name ? : 1 3 4
388 map
389 {
390 4 ▶ if (not defined $self->{catalog_list}{$_})
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $self->{"catalog_list"}{$_}) 1 4 5
391 {
392 1 ▶ if ($support_legacy)
Branch: 1 branch
BranchTrueFalseTotal
if ($support_legacy) { } 1 0 1
393 {
394 1 Class::IntrospectionMethods::Catalog::warn_obsolete("Warning: Undeclared catalog $_. Created...");
395 1 $self->{class_catalog}->add_catalog($_);
396 1 $self->{catalog_list}{$_} = [ $slot_name ] ;
397 }
398 else
399 {
400 croak "set_catalog, change command: unknown catalog ",
401 "$catalog_name, expected '",
402 0 join("','",keys %{$self->{catalog_list}}),"'\n"
403 }
404 }
405 } @cat ;
406  
407 # move slot from older catalog(s) to other(s)
408 4 $self->{slot_list}{$slot_name} = \@cat ;
409  
410 4 $self->update_catalog_list ;
411  
412 4 return @cat ;
413 }
414  
415 =head2 reset( slot_name )
416  
417 Put back slot in catalog as defined by global_catalog (and as stored
418 in ClassCatalog).
419  
420 =cut
421  
422 sub reset
423 1 ▶ {
Subroutine reset: called CC=2 SCAR=7.0
424 1 my ($self, $slot_name) = @_ ;
425  
426 1 ▶ croak "set_catalog, change command: Missing slot name"
Branch: 1 branch
BranchTrueFalseTotal
unless defined $slot_name 0 1 1
427 unless defined $slot_name;
428  
429 # move slot from older catalog(s) to other(s)
430 1 my @cat = $self->{class_catalog}->catalog($slot_name);
431 1 $self->{slot_list}{$slot_name} = \@cat ; ;
432  
433 1 $self->update_catalog_list ;
434  
435 1 return @cat ;
436 } ;
437  
438 # Used to provide legacy
439 sub add
440 1 ▶ {
Subroutine add: called CC=2 SCAR=7.0
441 1 my ($self, $slot,$catalog) = @_ ;
442  
443 1 ▶ my @cat = ref $catalog ? @$catalog : ($catalog) ;
Branch: 1 branch
BranchTrueFalseTotal
ref $catalog ? : 1 0 1
444 1 map { push @{$self->{catalog_list}{$_}}, $slot;} @cat ;
445 1 $self->{slot_list}{$slot} = \@cat ;
446  
447 1 $self->{class_catalog}->add($slot,$catalog) ;
448 }
449  
450 # forward unknown method to associated ClassCatalog
451 sub AUTOLOAD
452 58 ▶ {
Subroutine AUTOLOAD: called CC=2 SCAR=6.9
453 58 my $meth = $AUTOLOAD;
454 58 $meth =~ s/.*:://;
455 58 ▶ return if $meth eq 'DESTROY' ;
Branch: 1 branch
BranchTrueFalseTotal
if $meth eq "DESTROY" 4 54 58
456 54 shift -> {class_catalog} -> $meth(@_) ;
457 }
458  
459 package Class::IntrospectionMethods::ClassCatalog ;
460  
461 16 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
462 16 ▶use vars qw($AUTOLOAD @ISA);
Subroutine BEGIN: called CC=1 SCAR=0.0
463  
464 16 @ISA = qw/Class::IntrospectionMethods::AnyCatalog/ ;
465  
466 sub new
467 6 ▶ {
Subroutine new: called CC=4 SCAR=13.9
468 6 my $type = shift ;
469  
470 6 my $self = { @_ } ;
471  
472 6 my @user_list = @{$self -> {list}} ;
473 6 ▶ while (@user_list)
Branch: 1 branch
BranchTrueFalseTotal
if (@user_list) 9 6 15
474 {
475 9 my ($slot,$cat) = splice @user_list,0,2 ;
476 9 ▶ my @slot = ref $slot ? @$slot : ($slot) ;
Branch: 1 branch
BranchTrueFalseTotal
ref $slot ? : 7 2 9
477 9 ▶ my @cat = ref $cat ? @$cat : ($cat) ;
Branch: 1 branch
BranchTrueFalseTotal
ref $cat ? : 2 7 9
478 map
479 {
480 9 push @{$self->{ordered_slot_list}}, $_ ;
481 22 $self->{slot_list}{$_} = \@cat ;
482 } @slot
483 }
484  
485 6 bless $self, $type ;
486 6 $self->update_catalog_list ;
487  
488 6 return $self ;
489 }
490  
491 sub slot_list
492 4 ▶ {
Subroutine slot_list: called CC=1 SCAR=0.0
493 4 return $_[0]->{slot_list} ;
494 }
495  
496 sub ordered_slot_list
497 32 ▶ {
Subroutine ordered_slot_list: called CC=1 SCAR=0.0
498 32 return $_[0]->{ordered_slot_list} ;
499 }
500  
501 sub catalog_list
502 0 ▶ {
Subroutine catalog_list: not called CC=1 SCAR=6.9
503 0 return $_[0]->{catalog_list} ;
504 }
505  
506  
507 # To support legacy, catalogs can be added at run_time not sure it's a
508 # good idea for new application (too many way to mess things up)
509 sub add_catalog
510 1 ▶ {
Subroutine add_catalog: called CC=2 SCAR=7.2
511 1 my ($self, $catalog) = @_ ;
512 1 ▶ $self->{catalog_list}{$catalog} ||= [] ;
Condition50%1/2
$self->{"catalog_list"}{$catalog} ||= []
l!l
01
MC/DC0%0/1
$self->{"catalog_list"}{$catalog} ||= []
$self->{"catalog_list"}{$catalog}
Truth table50%1/2
A
A= $self->{"catalog_list"}{$catalog}
Aresult
11
00
513 }
514  
515 sub add
516 18 ▶ {
Subroutine add: called CC=2 SCAR=6.9
517 18 my ($self, $slot,$catalog) = @_ ;
518 18 push @{$self->{ordered_slot_list}}, $slot ;
519  
520 18 ▶ my @cat = ref $catalog ? @$catalog : ($catalog) ;
Branch: 1 branch
BranchTrueFalseTotal
ref $catalog ? : 1 17 18
521 18 map { push @{$self->{catalog_list}{$_}}, $slot;} @cat ;
522 18 $self->{slot_list}{$slot} = \@cat ;
523 }
524  
525 =head1 ClassCatalog methods
526  
527 =head2 help ( slot_name )
528  
529 Return the help info for slot_name that was given to
530 set_global_catalog. Return an empty string if no help was
531 provided. This help method is just a place holder, no fancy treatment
532 is done.
533  
534 =cut
535  
536 sub help
537 2 ▶ {
Subroutine help: called CC=2 SCAR=6.9
538 2 my $self = shift;
539 2 ▶ return $self->{help}{$_[0]} || '';
Condition100%2/2
$self->{'help'}{$_[0]} || ''
l!l
11
MC/DC100%1/1
$self->{'help'}{$_[0]} || ''
$self->{'help'}{$_[0]}
Truth table100%2/2
A
A= $self->{'help'}{$_[0]}
Aresult
11
00
540 }
541  
542 sub catalog_isa
543 33 ▶ {
Subroutine catalog_isa: called CC=3 SCAR=11.0
544 33 my ($self,$catalog_name)= @_ ;
545  
546 33 ▶ croak "set_catalog, isa command: Missing catalog name"
Branch: 1 branch
BranchTrueFalseTotal
unless defined $catalog_name 0 33 33
547 unless defined $catalog_name;
548  
549 33 my @result ;
550 33 my $next = $catalog_name ;
551 33 my $isa = $self->{isa} ;
552 33 ▶ while (defined $isa->{$next})
Branch: 1 branch
BranchTrueFalseTotal
if (defined $isa->{$next}) 7 33 40
553 {
554 7 push @result, $next = $isa->{$next} ;
555 }
556 33 return @result ;
557 }
558  
559 =head2 info ( slot_name )
560  
561 Returns construction informations of slot_name. This is handy for
562 introspection of actual properties of slot C<slot_name>.
563  
564 The details are returned in an array that contains:
565  
566 =over 8
567  
568 =item *
569  
570 The slot type: i.e. either C<slot_type =E<gt> scalar>,
571 C<slot_type =E<gt> array> or C<slot_type =E<gt> hash>.
572  
573 =item *
574  
575 If the index is tied (for C<array> or C<hash> slot type), the array
576 will contain: C<tie_index =E<gt> $tie_class>. If some constructor
577 arguments are used, the array will also contain C<tie_index_args
578 =E<gt> \@args>.
579  
580 =item *
581  
582 If the target value (i.e. the scalar) is tied (for all slot types),
583 the array will contain: C<tie_scalar =E<gt> $tie_class>. If some constructor
584 arguments are used, the array will also contain
585 C<tie_scalar_args =E<gt> \@args>.
586  
587 =item *
588  
589 If the target value (i.e. the scalar) is a plain object (for all slot
590 types), the array will contain: C<class =E<gt> $class>. If some
591 constructor arguments are used, the array will also contain
592 C<class_args =E<gt> \@args>.
593  
594 =back
595  
596 =cut
597  
598 sub info
599 7 ▶ {
Subroutine info: called CC=4 SCAR=13.9
600 7 my ($self, $slot_name) = @_ ;
601  
602 7 my $tgt = $self->{target_class} ;
603  
604 7 my $result = $construction_info{$tgt}{$slot_name};
605  
606 7 ▶ croak "no info on slot $slot_name (class $tgt)" unless
Branch: 1 branch
BranchTrueFalseTotal
unless defined $result 0 7 7
607 defined $result ;
608 7 ▶ return wantarray ? (ref $result eq 'HASH' ? %$result : @$result ) : $result ;
Branch: 2 branches
BranchTrueFalseTotal
wantarray ? : 3 4 7
ref $result eq 'HASH' ? : 1 2 3
609 }
610  
611 16 1;
612  
613 __END__
« IntrospectionMethods.pm ↑ Summary IntrospectionMethods/Parent.pm »