Hello all,
When I use introspection with the following program
CPAN::Forum
Object-InsideOut - OIO introspection
| Posted on Wed Mar 21 09:59:08 2007 by gaetan |
| OIO introspection |
|
Hello all, When I use introspection with the following program
package Object;
use Object::InsideOut;
use warnings;
use strict;
use Carp;
sub foo
{
}
sub bar :Private
{
}
package main;
my $obj = Object->new();
my @verify_array = Object->can();
my %verify_hash = Object->meta()->get_methods();
1;
the content of %verify_hash is
0 'create_field'
1 HASH(0x74a008)
'class' => 'Object::InsideOut'
'kind' => 'class'
2 'dump'
3 HASH(0x74a118)
'class' => 'Object::InsideOut'
'kind' => 'object'
4 'croak'
5 HASH(0x575f30)
'class' => 'Object'
6 'heritage'
7 HASH(0x7424e8)
'class' => 'Object::InsideOut'
'kind' => 'object'
'restricted' => 1
8 'disinherit'
9 HASH(0x742524)
'class' => 'Object::InsideOut'
'kind' => 'object'
'restricted' => 1
10 'add_class'
11 HASH(0x74a184)
'class' => 'Object::InsideOut'
'kind' => 'class'
12 'confess'
13 HASH(0x713890)
'class' => 'Object'
14 'meta'
15 HASH(0x742398)
'class' => 'Object'
16 'bar'
17 HASH(0x742488)
'class' => 'Object'
'private' => 1
18 'clone'
19 HASH(0x749d8c)
'class' => 'Object'
'kind' => 'object'
20 'carp'
21 HASH(0x742940)
'class' => 'Object'
22 'new'
23 HASH(0x742634)
'class' => 'Object'
'kind' => 'constructor'
'merge_args' => 1
24 'foo'
25 HASH(0x742578)
'class' => 'Object'
26 'inherit'
27 HASH(0x7424b8)
'class' => 'Object::InsideOut'
'kind' => 'object'
'restricted' => 1
28 'set'
29 HASH(0x74443c)
'class' => 'Object'
'kind' => 'object'
'restricted' => 1
30 'pump'
31 HASH(0x749d5c)
'class' => 'Object::InsideOut'
'kind' => 'class'
If I suppress all the elements with attributes other than 'class' key, I obtain the following information
4 'croak'
5 HASH(0x575f30)
'class' => 'Object'
12 'confess'
13 HASH(0x713890)
'class' => 'Object'
14 'meta'
15 HASH(0x742398)
'class' => 'Object'
20 'carp'
21 HASH(0x742940)
'class' => 'Object'
24 'foo'
25 HASH(0x742578)
'class' => 'Object'
The result is polluted by functions that are not defined by the class (see "carp", "croak", "confess", ...) Is there a way to distinguish user-defined methods from these functions ? If not, is it a restriction ? Another question (not related to OIO package, but I don't know where I could send this question ;-)) I have a perl function f() requiring a mandatory password parameter If this parameter is not present, the function can behaves: . either by requesting the user to enter the password . or by throwing an exception, letting the calling function managing the capture Due to the "separation concern" concept, I do not want to implement the first solution Is there a simple way in Perl to implement the second solution (without using a heavy solution such an a MVC model) ? For example, we could imagine a solution is pseudo Perl
sub main
{
eval {
f();
}
if ($@){
if ("exception_to_capture"){
$password = <>;
longjmp ($password);
}
}
}
sub f
{
my %param = @_;
if (!defined $param{password}){
$ret = "generate exception_to_capture + setjmp";
$param{password} = $ret;
}
....
}
Any ideas ? Thanks Gaetan |
| Write a response |
(2)
]