X-Git-Url: http://git.vpit.fr/?a=blobdiff_plain;f=lib%2FScope%2FContext.pm;h=aa422e1b950a8ecc682e3ff1b4863588aae82e7e;hb=f4699824df48f41d756111418704fca0d6d4d89e;hp=0bbfd91cc3e15824d414e09e9d7fe6303bdc52b5;hpb=4d0d929cc4f8e8f7ad6a2a4bd9caa2ab55b0259a;p=perl%2Fmodules%2FScope-Context.git diff --git a/lib/Scope/Context.pm b/lib/Scope/Context.pm index 0bbfd91..aa422e1 100644 --- a/lib/Scope/Context.pm +++ b/lib/Scope/Context.pm @@ -194,6 +194,110 @@ sub assert_valid { 1; } +=head2 C + + $cxt->package; + +Returns the namespace in use when the scope denoted by the invocant begins. + +=head2 C + + $cxt->file; + +Returns the name of the file where the scope denoted by the invocant belongs to. + +=head2 C + + $cxt->line; + +Returns the line number where the scope denoted by the invocant begins. + +=head2 C + + $cxt->sub_name; + +Returns the name of the subroutine called for this context, or C if this is not a subroutine context. + +=head2 C + + $cxt->sub_has_args; + +Returns a boolean indicating whether a new instance of C<@_> was set up for this context, or C if this is not a subroutine context. + +=head2 C + + $cxt->gimme; + +Returns the context (in the sense of L) in which the scope denoted by the invocant is executed. + +=head2 C + + $cxt->eval_text; + +Returns the contents of the string being compiled for this context, or C if this is not an eval context. + +=head2 C + + $cxt->is_require; + +Returns a boolean indicating whether this eval context was created by C, or C if this is not an eval context. + +=head2 C + + $cxt->hints_bits; + +Returns the value of the lexical hints bit mask (available as C<$^H> at compile time) in use when the scope denoted by the invocant begins. + +=head2 C + + $cxt->warnings_bits; + +Returns the bit string representing the warnings (available as C<${^WARNING_BITS}> at compile time) in use when the scope denoted by the invocant begins. + +=head2 C + + $cxt->hints_hash; + +Returns a reference to the lexical hints hash (available as C<%^H> at compile time) in use when the scope denoted by the invocant begins. +This method is available only on perl 5.10 and greater. + +=cut + +BEGIN { + my %infos = ( + package => 0, + file => 1, + line => 2, + sub_name => 3, + sub_has_args => 4, + gimme => 5, + eval_text => 6, + is_require => 7, + hints_bits => 8, + warnings_bits => 9, + (hints_hash => 10) x ("$]" >= 5.010), + ); + + for my $name (sort { $infos{$a} <=> $infos{$b} } keys %infos) { + my $idx = $infos{$name}; + local $@; + eval <<" TEMPLATE"; + sub $name { + my \$self = shift; + + \$self->assert_valid; + + my \$info = \$self->{info}; + \$info = \$self->{info} = [ Scope::Upper::context_info(\$self->cxt) ] + unless \$info; + + return \$info->[$idx]; + } + TEMPLATE + die $@ if $@; + } +} + =head2 C my $want = $cxt->want; @@ -493,7 +597,7 @@ You can find documentation for this module with the perldoc command. =head1 COPYRIGHT & LICENSE -Copyright 2011,2012 Vincent Pit, all rights reserved. +Copyright 2011,2012,2013 Vincent Pit, all rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.