File Coverage

blib/lib/Net/Proxmox/VE/Exception.pm
Criterion Covered Total %
statement 24 24 100.0
branch 2 2 100.0
condition 2 6 33.3
subroutine 8 8 100.0
pod 5 5 100.0
total 41 45 91.1


line stmt bran cond sub pod time code
1             #!/bin/false
2             # vim: softtabstop=4 tabstop=4 shiftwidth=4 ft=perl expandtab smarttab
3             # PODNAME: Net::Proxmox::VE::Exception
4             # ABSTRACT: Functions for the 'cluster' portion of the API
5              
6 8     8   548633 use strict;
  8         15  
  8         309  
7 8     8   44 use warnings;
  8         20  
  8         3304  
8              
9             package Net::Proxmox::VE::Exception;
10             $Net::Proxmox::VE::Exception::VERSION = '0.44';
11              
12             sub _new {
13              
14 7     7   11650 my ($c, %args) = @_;
15 7   33     37 my $class = ref($c) || $c;
16 7         15 my $self = \%args;
17              
18 7         75 return bless $self, $class;
19              
20             }
21              
22              
23             sub as_string {
24 1     1 1 6 my $self = shift;
25 1         4 sprintf '%s at %s line %s.', $self->message, $self->file, $self->line;
26             }
27              
28              
29 5     5 1 34 sub file { return shift->{file} }
30              
31              
32 5     5 1 34 sub line { return shift->{line} }
33              
34              
35 5     5 1 1839 sub message { return shift->{message} }
36              
37              
38             sub throw {
39              
40 4     4 1 10298 my ($class, $arg) = @_;
41 4   33     23 $class = ref $class || $class;
42              
43 4         8 my %args;
44 4 100       9 if ( ref $arg ) {
45 2         9 %args = %$arg;
46             }
47             else {
48 2         5 $args{message} = $arg;
49             }
50              
51 4         14 ( $args{package}, $args{file}, $args{line} ) = caller(0);
52 4         191 $args{subroutine} = ( caller(1) )[3];
53              
54 4         235 die $class->_new(%args);
55              
56             }
57              
58              
59             1;
60              
61             __END__
62              
63             =pod
64              
65             =encoding UTF-8
66              
67             =head1 NAME
68              
69             Net::Proxmox::VE::Exception - Functions for the 'cluster' portion of the API
70              
71             =head1 VERSION
72              
73             version 0.44
74              
75             =head1 SYNOPSIS
76              
77             use Net::Proxmox::VE::Exception;
78             Net::Proxmox::VE::Exception->throw( "What went wrong" )
79              
80             =head1 INTERNAL METHODS
81              
82             =head2 _new
83              
84             This is a standard new() interface, but is intended for internal usage
85             rather than as the public interface.
86              
87             Any argument will be included in the object.
88              
89             =head1 PUBLIC METHODS
90              
91             =head2 as_string
92              
93             The exception details as human readable string
94              
95             $obj->as_string()
96              
97             =head2 file
98              
99             File that called the function
100              
101             $obj->file()
102              
103             =head2 line
104              
105             Line in the file that called the function
106              
107             $obj->line()
108              
109             =head2 message
110              
111             Message why the exception occured
112              
113             $obj->message()
114              
115             =head2 throw
116              
117             This is intended as the public interface.
118              
119             To be used like this
120              
121             use Net::Proxmox::VE::Exception;
122             Net::Proxmox::VE::Exception->throw( "message")
123             Net::Proxmox::VE::Exception->throw( { message => "message" } )
124              
125             =head1 SEE ALSO
126              
127             L<Net::Proxmox::VE>
128              
129             =head1 AUTHOR
130              
131             Dean Hamstead <dean@fragfest.com.au>
132              
133             =head1 COPYRIGHT AND LICENSE
134              
135             This software is Copyright (c) 2026 by Dean Hamstead.
136              
137             This is free software, licensed under:
138              
139             The MIT (X11) License
140              
141             =cut