File Coverage

/tmp/TpFQ2XBsys/lib/My/Prefix/HashBase.pm
Criterion Covered Total %
statement 44 87 50.5
branch 10 34 29.4
condition 6 17 35.2
subroutine 8 15 53.3
pod 1 1 100.0
total 69 154 44.8


line stmt bran cond sub pod time code
1             package My::Prefix::HashBase;
2 1     1   1308 use strict;
  1         2  
  1         33  
3 1     1   5 use warnings;
  1         2  
  1         53  
4              
5             our $VERSION = '123';
6              
7             #################################################################
8             # #
9             # This is a generated file! Do not modify this file directly! #
10             # Use hashbase_inc.pl script to regenerate this file. #
11             # The script is part of the Object::HashBase distribution. #
12             # Note: You can modify the version number above this comment #
13             # if needed, that is fine. #
14             # #
15             #################################################################
16              
17             {
18 1     1   6 no warnings 'once';
  1         1  
  1         105  
19             $My::Prefix::HashBase::HB_VERSION = '0.009';
20             *My::Prefix::HashBase::ATTR_SUBS = \%Object::HashBase::ATTR_SUBS;
21             *My::Prefix::HashBase::ATTR_LIST = \%Object::HashBase::ATTR_LIST;
22             *My::Prefix::HashBase::VERSION = \%Object::HashBase::VERSION;
23             *My::Prefix::HashBase::CAN_CACHE = \%Object::HashBase::CAN_CACHE;
24             }
25              
26              
27             require Carp;
28             {
29 1     1   6 no warnings 'once';
  1         1  
  1         84  
30             $Carp::Internal{+__PACKAGE__} = 1;
31             }
32              
33             BEGIN {
34             # these are not strictly equivalent, but for out use we don't care
35             # about order
36             *_isa = ($] >= 5.010 && require mro) ? \&mro::get_linear_isa : sub {
37 1     1   6 no strict 'refs';
  1         2  
  1         129  
38 0         0 my @packages = ($_[0]);
39 0         0 my %seen;
40 0         0 for my $package (@packages) {
41 0         0 push @packages, grep !$seen{$_}++, @{"$package\::ISA"};
  0         0  
42             }
43 0         0 return \@packages;
44             }
45 1 50 33 1   520 }
46              
47             my %SPEC = (
48             '^' => {reader => 1, writer => 0, dep_writer => 1, read_only => 0, strip => 1},
49             '-' => {reader => 1, writer => 0, dep_writer => 0, read_only => 1, strip => 1},
50             '>' => {reader => 0, writer => 1, dep_writer => 0, read_only => 0, strip => 1},
51             '<' => {reader => 1, writer => 0, dep_writer => 0, read_only => 0, strip => 1},
52             '+' => {reader => 0, writer => 0, dep_writer => 0, read_only => 0, strip => 1},
53             );
54              
55             sub import {
56 2     2   2501 my $class = shift;
57 2         51 my $into = caller;
58              
59             # Make sure we list the OLDEST version used to create this class.
60 2   33     10 my $ver = $My::Prefix::HashBase::HB_VERSION || $My::Prefix::HashBase::VERSION;
61 2 50 33     9 $My::Prefix::HashBase::VERSION{$into} = $ver if !$My::Prefix::HashBase::VERSION{$into} || $My::Prefix::HashBase::VERSION{$into} > $ver;
62              
63 2         14 my $isa = _isa($into);
64 2   50     10 my $attr_list = $My::Prefix::HashBase::ATTR_LIST{$into} ||= [];
65 2   50     11 my $attr_subs = $My::Prefix::HashBase::ATTR_SUBS{$into} ||= {};
66              
67             my %subs = (
68             ($into->can('new') ? () : (new => \&_new)),
69 1 50       6 (map %{$My::Prefix::HashBase::ATTR_SUBS{$_} || {}}, @{$isa}[1 .. $#$isa]),
  2         5  
70             (
71             map {
72 2 100       22 my $p = substr($_, 0, 1);
  2         4  
73 2         6 my $x = $_;
74              
75 2   50     8 my $spec = $SPEC{$p} || {reader => 1, writer => 1};
76              
77 2 50       5 substr($x, 0, 1) = '' if $spec->{strip};
78 2         5 push @$attr_list => $x;
79 2         6 my ($sub, $attr) = (uc $x, $x);
80              
81 2     0   18 $attr_subs->{$sub} = sub() { $attr };
  0         0  
82 2         5 my %out = ($sub => $attr_subs->{$sub});
83              
84 2 50   0   9 $out{$attr} = sub { $_[0]->{$attr} } if $spec->{reader};
  0         0  
85 2 50   0   9 $out{"set_$attr"} = sub { $_[0]->{$attr} = $_[1] } if $spec->{writer};
  0         0  
86 2 50   0   5 $out{"set_$attr"} = sub { Carp::croak("'$attr' is read-only") } if $spec->{read_only};
  0         0  
87 2 50   0   5 $out{"set_$attr"} = sub { Carp::carp("set_$attr() is deprecated"); $_[0]->{$attr} = $_[1] } if $spec->{dep_writer};
  0         0  
  0         0  
88              
89 2         12 %out;
90             } @_
91             ),
92             );
93              
94 1     1   8 no strict 'refs';
  1         2  
  1         502  
95 2         7 *{"$into\::$_"} = $subs{$_} for keys %subs;
  8         28  
96             }
97              
98             sub attr_list {
99 0     0 1   my $class = shift;
100              
101 0           my $isa = _isa($class);
102              
103 0           my %seen;
104 0           my @list = grep { !$seen{$_}++ } map {
105 0           my @out;
  0            
106              
107 0 0 0       if (0.004 > ($My::Prefix::HashBase::VERSION{$_} || 0)) {
108 0           Carp::carp("$_ uses an inlined version of My::Prefix::HashBase too old to support attr_list()");
109             }
110             else {
111 0           my $list = $My::Prefix::HashBase::ATTR_LIST{$_};
112 0 0         @out = $list ? @$list : ()
113             }
114              
115 0           @out;
116             } reverse @$isa;
117              
118 0           return @list;
119             }
120              
121             sub _new {
122 0     0     my $class = shift;
123              
124 0           my $self;
125              
126 0 0         if (@_ == 1) {
127 0           my $arg = shift;
128 0           my $type = ref($arg);
129              
130 0 0         if ($type eq 'HASH') {
131 0           $self = bless({%$arg}, $class)
132             }
133             else {
134 0 0         Carp::croak("Not sure what to do with '$type' in $class constructor")
135             unless $type eq 'ARRAY';
136              
137 0           my %proto;
138 0           my @attributes = attr_list($class);
139 0           while (@$arg) {
140 0           my $val = shift @$arg;
141 0 0         my $key = shift @attributes or Carp::croak("Too many arguments for $class constructor");
142 0           $proto{$key} = $val;
143             }
144              
145 0           $self = bless(\%proto, $class);
146             }
147             }
148             else {
149 0           $self = bless({@_}, $class);
150             }
151              
152             $My::Prefix::HashBase::CAN_CACHE{$class} = $self->can('init')
153 0 0         unless exists $My::Prefix::HashBase::CAN_CACHE{$class};
154              
155 0 0         $self->init if $My::Prefix::HashBase::CAN_CACHE{$class};
156              
157 0           $self;
158             }
159              
160             1;
161              
162             __END__