File Coverage

blib/lib/Salvation/UpdateGvFLAGS.pm
Criterion Covered Total %
statement 22 22 100.0
branch n/a
condition n/a
subroutine 7 7 100.0
pod 3 3 100.0
total 32 32 100.0


line stmt bran cond sub pod time code
1             package Salvation::UpdateGvFLAGS;
2              
3             =head1 NAME
4              
5             Salvation::UpdateGvFLAGS - Modifies GvFLAGS of a given SV
6              
7             =head1 SYNOPSIS
8              
9             Salvation::UpdateGvFLAGS::toggle( *asd::qwe, 0x80 );
10              
11             =cut
12              
13 1     1   32299 use strict;
  1         2  
  1         48  
14 1     1   5 use warnings;
  1         1  
  1         42  
15              
16 1     1   6 use B 'svref_2object';
  1         6  
  1         158  
17              
18             our $VERSION = 0.01;
19              
20             require XSLoader;
21              
22             XSLoader::load( 'Salvation::UpdateGvFLAGS', $VERSION );
23              
24             =head1 FUNCTIONS
25              
26             =cut
27              
28             =head2 toggle( sv, flag )
29              
30             Toggles given flag within GvFLAGS of an SV.
31              
32             =cut
33              
34             =head2 toggle_glob_flag_by_name( name, flag )
35              
36             An alias for C.
37              
38             Example usage:
39             package asd;
40             sub qwe {}
41             package main;
42             Salvation::UpdateGvFLAGS::toggle_glob_flag_by_name( 'asd::qwe', 0x80 );
43              
44             =cut
45              
46             sub toggle_glob_flag_by_name {
47              
48 1     1 1 3 my ( $name, $flag ) = @_;
49 1         3 my $ref = do {
50              
51 1     1   6 no strict 'refs';
  1         2  
  1         231  
52 1         7 \*$name;
53             };
54              
55 1         6 return toggle_glob_flag_by_globref( $ref, $flag );
56             }
57              
58             =head2 toggle_glob_flag_by_globref( ref, flag )
59              
60             An alias for C.
61              
62             Example usage:
63             package asd;
64             sub qwe {}
65             package main;
66             Salvation::UpdateGvFLAGS::toggle_glob_flag_by_globref( \*asd::qwe, 0x80 );
67              
68             =cut
69              
70             sub toggle_glob_flag_by_globref {
71              
72 1     1 1 3 my ( $ref, $flag ) = @_;
73              
74 1         10 return Salvation::UpdateGvFLAGS::toggle( *$ref, $flag );
75             }
76              
77             =head2 toggle_glob_flag_by_coderef( ref, flag )
78              
79             An alias for C.
80              
81             Example usage:
82             package asd;
83             sub qwe {}
84             package main;
85             Salvation::UpdateGvFLAGS::toggle_glob_flag_by_coderef( \&asd::qwe, 0x80 );
86              
87             =cut
88              
89             sub toggle_glob_flag_by_coderef {
90              
91 1     1 1 44 my ( $ref, $flag ) = @_;
92 1         7 my $o = svref_2object( $ref );
93 1         8 my $gv = $o -> GV();
94              
95 1         23 return toggle_glob_flag_by_name( sprintf( '%s::%s', (
96             $gv -> STASH() -> NAME(),
97             $gv -> NAME(),
98              
99             ) ), $flag );
100             }
101              
102             1;
103              
104             __END__