File Coverage

lib/OODoc/Object.pm
Criterion Covered Total %
statement 15 34 44.1
branch 0 4 0.0
condition n/a
subroutine 5 14 35.7
pod 4 5 80.0
total 24 57 42.1


line stmt bran cond sub pod time code
1             # This code is part of Perl distribution OODoc version 3.05.
2             # The POD got stripped from this file by OODoc version 3.05.
3             # For contributors see file ChangeLog.
4              
5             # This software is copyright (c) 2003-2025 by Mark Overmeer.
6              
7             # This is free software; you can redistribute it and/or modify it under
8             # the same terms as the Perl 5 programming language system itself.
9             # SPDX-License-Identifier: Artistic-1.0-Perl OR GPL-1.0-or-later
10              
11              
12             package OODoc::Object;{
13             our $VERSION = '3.05';
14             }
15              
16              
17 2     2   850 use strict;
  2         5  
  2         76  
18 2     2   8 use warnings;
  2         29  
  2         163  
19              
20 2     2   1037 use Log::Report 'oodoc';
  2         193700  
  2         12  
21              
22 2     2   589 use List::Util qw/first/;
  2         2  
  2         207  
23              
24             #--------------------
25              
26             use overload
27 0     0     '==' => sub {$_[0]->unique == $_[1]->unique},
28 0     0     '!=' => sub {$_[0]->unique != $_[1]->unique},
29 2     2   11 'bool' => sub {1};
  2     0   2  
  2         34  
  0            
30              
31             #--------------------
32              
33             sub new(@)
34 0     0 1   { my ($class, %args) = @_;
35 0           my $self = (bless {}, $class)->init(\%args);
36              
37 0 0         if(my @missing = keys %args)
38 0           { error __xn"unknown object attribute '{names}' for {pkg}", "unknown object attributes for {pkg}: {names}",
39             scalar @missing, names => \@missing, pkg => $class;
40             }
41              
42 0           $self;
43             }
44              
45             my $unique = 42;
46              
47             sub init($)
48 0     0 0   { my ($self, $args) = @_;
49              
50             # prefix with 'id', otherwise confusion between string and number
51 0           $self->{OO_unique} = 'id' . $unique++;
52 0           $self;
53             }
54              
55             #--------------------
56              
57 0     0 1   sub unique() { $_[0]->{OO_unique} }
58              
59              
60 0     0 1   sub manual() { panic }
61              
62             #--------------------
63              
64             my $index; # still a global :-( Set by ::Export
65 0     0     sub _publicationIndex($) { $index = $_[1] }
66              
67             sub publish($)
68 0     0 1   { my ($self, $args) = @_;
69 0           my $id = $self->unique;
70              
71 0           my $manual = $args->{manual};
72 0 0         $id .= '-' . $manual->unique if $manual->inherited($self);
73              
74 0           $index->{$id} = +{ id => $id };
75             }
76              
77             1;