blib/lib/Parse/FireDiamond.pm

filter: Statementstmt 43.6% 24 / 55 Branchbran 0.0% 0 / 16 Conditioncond 0.0% 0 / 13 MC/DCmcdc 0.0% 0 / 8 Subroutinesub 80.0% 4 / 5 Podpod 100% 1 / 1 totaltotal 29.5% 29 / 98 CC 15 SCAR 52.5
CC
15
Cov
29%
parse_fire_diamond_text_notation
240.0
BEGIN
1.0
BEGIN
1.0
CRAP 189.7
↑ Summary
1 package Parse::FireDiamond;
2  
3 1 ▶use 5.010001;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 1 our $AUTHORITY = 'cpan:PERLANCAR'; # AUTHORITY
8 1 our $DATE = '2023-03-29'; # DATE
9 1 our $DIST = 'Parse-FireDiamond'; # DIST
10 1 our $VERSION = '0.005'; # VERSION
11  
12 1 ▶use Exporter qw(import);
Subroutine BEGIN: called CC=1 SCAR=0.0
13 1 our @EXPORT_OK = qw(
14 parse_fire_diamond_text_notation
15 );
16  
17 1 our %SPEC;
18  
19 1 $SPEC{':package'} = {
20 v => 1.1,
21 summary => 'Parse Fire Diamond (NFPA 704) notation',
22 };
23  
24 1 our %health_hazard_attrs = (
25 4 => {
26 meaning => "deadly",
27 explanation => "Very short exposure could cause death or major residual injury (e.g. hydrogen cyanide, phosgene, diborane, methyl isocyanate, hydrofluoric acid)",
28 },
29 3 => {
30 meaning=>"extreme danger",
31 explanation => "Short exposure could cause serious temporary or moderate residual injury (e.g. liquid hydrogen, sulfuric acid, calcium hypochlorite, carbon monoxide, hexafluorosilicic acid, zinc chloride, sodium hydroxide)",
32 },
33 2 => {
34 meaning=>"hazardous",
35 explanation => "Intense or continued but not chronic exposure could cause temporary incapacitation or possible residual injury (e.g. diethyl ether, ammonium phosphate, carbon dioxide, chloroform, DEET).",
36 },
37 1 => {
38 meaning=>"slightly hazardous",
39 explanation => "Exposure would cause irritation with only minor residual injury (e.g. acetone, sodium bromate, potassium chloride)",
40 },
41 0 => {
42 meaning=>"normal material",
43 explanation => "Poses no health hazard, no precautions necessary and would offer no hazard beyond that of ordinary combustible materials (e.g. wood, sugar, salt, propylene glycol)",
44 },
45 );
46  
47 1 our %fire_hazard_attrs = (
48 4 => {
49 meaning => "below 25 °C",
50 explanation => "Will rapidly or completely vaporize at normal atmospheric pressure and temperature, or is readily dispersed in air and will burn readily (e.g. acetylene, propane, hydrogen gas, diborane). Includes pyrophoric substances. Flash point below room temperature at 22.8 °C (73 °F).",
51 },
52 3 => {
53 meaning => "below 37 °C",
54 explanation => "Liquids and solids (including finely divided suspended solids) that can be ignited under almost all ambient temperature conditions (e.g. gasoline, acetone, ethanol). Liquids having a flash point below 22.8 °C (73 °F) and having a boiling point at or above 37.8 °C (100 °F) or having a flash point between 22.8 and 37.8 °C (73 and 100 °F).",
55 },
56 2 => {
57 meaning => "below 93 °C",
58 explanation => "Must be moderately heated or exposed to relatively high ambient temperature before ignition can occur (e.g. diesel fuel, paper, sulfur and multiple finely divided suspended solids that do not require heating before ignition can occur). Flash point between 37.8 and 93.3 °C (100 and 200 °F).",
59 },
60 1 => {
61 meaning => "above 93 °C",
62 explanation => "Materials that require considerable preheating, under all ambient temperature conditions, before ignition and combustion can occur (e.g. mineral oil, ammonia, ethylene glycol). Includes some finely divided suspended solids that do not require heating before ignition can occur. Flash point at or above 93.3 °C (200 °F).",
63 },
64 0 => {
65 meaning=>"not flammable",
66 explanation => "Materials that will not burn under typical fire conditions (e.g. carbon tetrachloride, silicon dioxide, perfluorohexane), including intrinsically noncombustible materials such as concrete, stone, and sand. Materials that will not burn in air unless exposed to a temperature of 820 °C (1,500 °F) for more than 5 minutes.",
67 },
68 );
69  
70 1 our %reactivity_attrs = (
71 4 => {
72 meaning => "may detonate",
73 explanation => "Readily capable of detonation or explosive decomposition at normal temperatures and pressures (e.g. nitroglycerin, chlorine dioxide, nitrogen triiodide, manganese heptoxide, TNT)",
74 },
75 3 => {
76 meaning => "shock + heat may detonate",
77 explanation => "Capable of detonation or explosive decomposition but requires a strong initiating source, must be heated under confinement before initiation, reacts explosively with water, or will detonate if severely shocked (e.g. ammonium nitrate, caesium, hydrogen peroxide)",
78 },
79 2 => {
80 meaning => "violent reaction",
81 explanation => "Undergoes violent chemical change at elevated temperatures and pressures, reacts violently with water, or may form explosive mixtures with water (e.g. white phosphorus, potassium, sodium)",
82 },
83 1 => {
84 meaning => "unstable if heated",
85 explanation => "Normally stable, but can become unstable at elevated temperatures and pressures (e.g. propene, ammonium acetate, carbonic acid)",
86 },
87 0 => {
88 meaning => "stable",
89 explanation => "Normally stable, even under fire exposure conditions, and is not reactive with water (e.g. helium, N2, carbon dioxide)",
90 },
91 );
92  
93 1 our %specific_hazard_attrs = (
94 O => {
95 meaning => "oxidizer",
96 explanation => "allows chemicals to burn without an air supply (e.g. potassium perchlorate, ammonium nitrate, hydrogen peroxide)",
97 },
98 OX => {
99 meaning => "oxidizer",
100 explanation => "allows chemicals to burn without an air supply (e.g. potassium perchlorate, ammonium nitrate, hydrogen peroxide)",
101 },
102 OXY => {
103 meaning => "oxidizer",
104 explanation => "allows chemicals to burn without an air supply (e.g. potassium perchlorate, ammonium nitrate, hydrogen peroxide)",
105 },
106  
107 W => {
108 meaning => "reacts with water",
109 explanation => "Reacts with water in an unusual or dangerous manner (e.g. caesium, sodium, diborane, sulfuric acid)",
110 },
111 # W with overstrike
112  
113 SA => {
114 meaning => "simple asphyxiant gas",
115 explanation => "Simple asphyxiant gas (specifically helium, nitrogen, neon, argon, krypton, xenon), shall also be used for liquefied carbon dioxide vapor withdrawal systems and where large quantities of dry ice are used in confined areas",
116 },
117  
118 COR => {
119 meaning => "corrosive",
120 explanation => "strong acid or base (e.g. sulfuric acid, potassium hydroxide) ",
121 },
122  
123 ACID => {
124 meaning => "acid",
125 explanation => "",
126 },
127  
128 ALK => {
129 meaning => "alkaline",
130 explanation => "",
131 },
132  
133 BIO => {
134 meaning => "biological hazard",
135 explanation => "Biological hazard (e.g. flu virus, rabies virus)",
136 },
137  
138 POI => {
139 meaning => "poisonous",
140 explanation => "Poisonous (e.g. strychnine, alpha-amanitin)",
141 },
142  
143 RA => {
144 meaning => "radioactive",
145 explanation => "Radioactive (e.g. plutonium, cobalt-60, carbon-14)",
146 },
147 RAD => {
148 meaning => "radioactive",
149 explanation => "Radioactive (e.g. plutonium, cobalt-60, carbon-14)",
150 },
151  
152 CRY => {
153 meaning => "cryogenic",
154 explanation => "Cryogenic (e.g. liquid nitrogen)",
155 },
156 CRYO => {
157 meaning => "cryogenic",
158 explanation => "Cryogenic (e.g. liquid nitrogen)",
159 },
160 );
161  
162 $SPEC{parse_fire_diamond_text_notation} = {
163 1 v => 1.1,
164 summary => 'Parse Fire Diamond (NFPA 704) text notation',
165 args => {
166 notation => {
167 schema => 'str*',
168 req => 1,
169 pos => 0,
170 },
171 },
172 examples => [
173 {
174 summary => "Parse the fire diamond for citric acid",
175 args => {notation=>"H2/F1/R0/"},
176 },
177 {
178 summary => "Parse the fire diamond for sucrose",
179 args => {notation=>"H0/F1/R0/"},
180 },
181 {
182 summary => "Parse the fire diamond for sulfuric acid",
183 args => {notation=>"H3/F0/R2/W+OX"},
184 },
185 ],
186 };
187 0 ▶sub parse_fire_diamond_text_notation {
Subroutine parse_fire_diamond_text_notation: not called CC=15 SCAR=54.8
Pod documented
188 0 my %args = @_;
189  
190 0 ▶ my $notation = $args{notation} or return [400, "Please specify notation"];
Branch: 1 branch
BranchTrueFalseTotal
my $notation = $args{"notation"} or return [400, "Please specify notation"] 0 0 0
191 0 $notation = uc($notation);
192 0 $notation =~ s/\s+//g;
193  
194 0 my $res = [200, "OK (parsed)", {}, {}];
195  
196 0 ▶ my ($h, $f, $r, $specifics) = $notation =~ m!\AH(\d+)/F(\d+)/R(\d+)/(.*)\z!
Branch: 1 branch
BranchTrueFalseTotal
() = $notation =~ m[\AH(\d+)/F(\d+)/R(\d+)/(.*)\z] or return [400, "Bad syntax, must be in Hx/Fx/Rx/(...(+...))? notation"] 0 0 0
197 or return [400, "Bad syntax, must be in Hx/Fx/Rx/(...(+...))? notation"];
198  
199 0 ▶ $h >= 0 && $h <= 4 or return [400, "Bad H value, must be between 0 and 4"];
Branch: 1 branch
BranchTrueFalseTotal
$h >= 0 and $h <= 4 or return [400, "Bad H value, must be between 0 and 4"] 0 0 0
Condition0%0/3
$h >= 0 and $h <= 4
!ll&&!rl&&r
000
MC/DC0%0/2
$h >= 0 and $h <= 4
$h >= 0 $h <= 4
Truth table0%0/3
A and B
A= $h >= 0B= $h <= 4
ABresult
0X0
100
111
200 0 $res->[2]{health_hazard_number} = $h;
201 0 $res->[2]{health_hazard_meaning} = $health_hazard_attrs{$h}{meaning};
202 0 $res->[3]{'func.health_hazard_explanation'} = $health_hazard_attrs{$h}{explanation};
203  
204 0 ▶ $f >= 0 && $f <= 4 or return [400, "Bad F value, must be between 0 and 4"];
Branch: 1 branch
BranchTrueFalseTotal
$f >= 0 and $f <= 4 or return [400, "Bad F value, must be between 0 and 4"] 0 0 0
Condition0%0/3
$f >= 0 and $f <= 4
!ll&&!rl&&r
000
MC/DC0%0/2
$f >= 0 and $f <= 4
$f >= 0 $f <= 4
Truth table0%0/3
A and B
A= $f >= 0B= $f <= 4
ABresult
0X0
100
111
205 0 $res->[2]{fire_hazard_number} = $f;
206 0 $res->[2]{fire_hazard_meaning} = $fire_hazard_attrs{$f}{meaning};
207 0 $res->[3]{'func.fire_hazard_explanation'} = $fire_hazard_attrs{$f}{explanation};
208  
209 0 ▶ $r >= 0 && $r <= 4 or return [400, "Bad R value, must be between 0 and 4"];
Branch: 1 branch
BranchTrueFalseTotal
$r >= 0 and $r <= 4 or return [400, "Bad R value, must be between 0 and 4"] 0 0 0
Condition0%0/3
$r >= 0 and $r <= 4
!ll&&!rl&&r
000
MC/DC0%0/2
$r >= 0 and $r <= 4
$r >= 0 $r <= 4
Truth table0%0/3
A and B
A= $r >= 0B= $r <= 4
ABresult
0X0
100
111
210 0 $res->[2]{reactivity_number} = $r;
211 0 $res->[2]{reactivity_meaning} = $reactivity_attrs{$r}{meaning};
212 0 $res->[3]{'func.reactivity_explanation'} = $reactivity_attrs{$r}{explanation};
213  
214 0 my @specifics = split /\+/, $specifics;
215 0 my %seen_specifics;
216 0 for my $specific (@specifics) {
217 0 ▶ $specific =~ /\A[A-Z]+\z/ or return [400, "Bad syntax in specific hazard '$specific', must be all letters"];
Branch: 1 branch
BranchTrueFalseTotal
$specific =~ /\A[A-Z]+\z/ or return [400, "Bad syntax in specific hazard '${specific}', must be all letters"] 0 0 0
218 0 ▶ exists $specific_hazard_attrs{$specific} or return [400, "Unknown specific hazard symbol '$specific'"];
Branch: 1 branch
BranchTrueFalseTotal
exists $Parse::FireDiamond::specific_hazard_attrs{$specific} or return [400, "Unknown specific hazard symbol '${specific}'"] 0 0 0
219 0 ▶ $seen_specifics{$specific}++ and return [400, "Duplicate specific hazard symbol '$specific'"];
Branch: 1 branch
BranchTrueFalseTotal
$seen_specifics{$specific}++ and return [400, "Duplicate specific hazard symbol '${specific}'"] 0 0 0
220 0 ▶ $res->[2]{specific_hazards} //= [];
Condition0%0/2
$res->[2]{"specific_hazards"} //= []
l!l
00
MC/DC0%0/1
$res->[2]{"specific_hazards"} //= []
$res->[2]{"specific_hazards"}
Truth table0%0/2
A
A= $res->[2]{"specific_hazards"}
Aresult
11
00
221 0 ▶ $res->[3]{'func.specific_hazards'} //= [];
Condition0%0/2
$res->[3]{"func.specific_hazards"} //= []
l!l
00
MC/DC0%0/1
$res->[3]{"func.specific_hazards"} //= []
$res->[3]{"func.specific_hazards"}
Truth table0%0/2
A
A= $res->[3]{"func.specific_hazards"}
Aresult
11
00
222 0 push @{ $res->[2]{specific_hazards} }, {
223 symbol => $specific,
224 meaning => $specific_hazard_attrs{$specific}{meaning},
225 0 };
226 0 push @{ $res->[3]{'func.specific_hazards'} }, {
227 symbol => $specific,
228 explanation => $specific_hazard_attrs{$specific}{explanation},
229 0 };
230 }
231  
232 0 $res;
233 }
234  
235 1 1;
236 # ABSTRACT: Parse Fire Diamond (NFPA 704) notation
237  
238 __END__
↑ Summary