File Coverage

web/cgi-bin/yatt.lib/YATT/Util/Enum.pm
Criterion Covered Total %
statement 26 28 92.8
branch 5 10 50.0
condition 6 10 60.0
subroutine 4 4 100.0
pod n/a
total 41 52 78.8


line stmt bran cond sub pod time code
1             # -*- mode: perl; coding: utf-8 -*-
2             package YATT::Util::Enum;
3 8     8   95 use strict;
  8         8  
  8         236  
4 8     8   24 use warnings FATAL => qw(all);
  8         9  
  8         188  
5              
6 8     8   32 use YATT::Util::Symbol qw/define_const/;
  8         7  
  8         1666  
7              
8             sub import {
9 26     26   49 my ($pack) = shift;
10 26         43 my $callpack = caller;
11              
12             #----------------------------------------
13 26         27 my %opts;
14 26   66     206 for (; @_ and $_[0] =~ /^-(\w+)/; splice @_, 0, 2) {
15 19         130 $opts{$1} = $_[1];
16             }
17 26   50     103 my $offset = delete $opts{offset} || 0;
18 26   100     71 my $prefix = delete $opts{prefix} || "";
19 26 50       59 my $export = delete $opts{export}
20             ? $callpack . "::EXPORT" : "";
21 26 50 33     98 my $export_ok = $export || delete $opts{export_ok}
22             ? $callpack . "::EXPORT_OK" : "";
23 26 50       64 die "Unknown options for " . __PACKAGE__ . "\n".
24             join ", ", keys %opts if keys %opts;
25              
26             #----------------------------------------
27 26         48 foreach my $item (@_) {
28 155         181 my $full_name = $callpack . "::" . $prefix . $item;
29             {
30 155         105 define_const($full_name, $offset);
  155         234  
31 155 50       214 push @{$export}, $full_name if $export;
  0         0  
32 155 50       205 push @{$export_ok}, $full_name if $export_ok;
  0         0  
33             }
34             } continue {
35 155         10346 $offset++;
36             }
37             }
38              
39             1;