| 1 | #!/usr/bin/perl | ||
| 2 | =head1 NAME | ||
| 3 | |||
| 4 | Asterisk::LCR::Route - Route objects for Asterisk::LCR | ||
| 5 | |||
| 6 | |||
| 7 | =head1 SYNOPSIS | ||
| 8 | |||
| 9 | use Asterisk::LCR::Route; | ||
| 10 | my $rate = Asterisk::LCR::Route->new ( | ||
| 11 | provider => 'someprovider', | ||
| 12 | connection_fee => 0, | ||
| 13 | first_increment => 30, | ||
| 14 | increment => 6, | ||
| 15 | rate => 10.125, | ||
| 16 | currency => 'EUR', | ||
| 17 | label => 'The Moon - Mobile Services', | ||
| 18 | ); | ||
| 19 | |||
| 20 | |||
| 21 | =head1 SUMMARY | ||
| 22 | |||
| 23 | Represents a rate, i.e. amounts of currency to pay, for a | ||
| 24 | given destination prefix. | ||
| 25 | |||
| 26 | Note that this might not always be true. | ||
| 27 | |||
| 28 | For example: | ||
| 29 | |||
| 30 | +262 is supposed to be 'reunion island' but | ||
| 31 | +262692 is 'reunion island mobiles' | ||
| 32 | |||
| 33 | For this reason, when looking for a rate for a given | ||
| 34 | destination, LCR engines must find rates with the longest | ||
| 35 | possible prefix that matches a given number. | ||
| 36 | |||
| 37 | |||
| 38 | =head1 ATTRIBUTES | ||
| 39 | |||
| 40 | =head2 connection_fee (numeric scalar) | ||
| 41 | |||
| 42 | Fee which might be applied for any successful | ||
| 43 | call, regardless of its length. | ||
| 44 | |||
| 45 | =head2 first_increment (numeric scalar) | ||
| 46 | |||
| 47 | Incompressible first length of time billed. | ||
| 48 | |||
| 49 | =head2 increment (numeric scalar) | ||
| 50 | |||
| 51 | Incompressible subsequent lengths of time billed. | ||
| 52 | |||
| 53 | =head2 currency (scalar) | ||
| 54 | |||
| 55 | Currency which is used for this rate, i.e. EUR, USD, | ||
| 56 | GBP... | ||
| 57 | |||
| 58 | =head2 rate (numeric scalar) | ||
| 59 | |||
| 60 | Amounts of currency per minute | ||
| 61 | |||
| 62 | =head2 provider (scalar) | ||
| 63 | |||
| 64 | Provider which provides this rate. | ||
| 65 | |||
| 66 | =head2 label (scalar) | ||
| 67 | |||
| 68 | Destination of this rate. This is a string, not an object. | ||
| 69 | |||
| 70 | =head1 METHODS | ||
| 71 | |||
| 72 | =cut | ||
| 73 | package Asterisk::LCR::Route; | ||
| 74 | use base qw /Asterisk::LCR::Object/; | ||
| 75 | use warnings; | ||
| 76 | use strict; | ||
| 77 | |||
| 78 | # list of known currencies, taken from | ||
| 79 | # http://www.xe.com/iso4217.htm | ||
| 80 | our %CURRENCY = ( | ||
| 81 | AED => 'United Arab Emirates, Dirhams', | ||
| 82 | AFA => 'Afghanistan, Afghanis', | ||
| 83 | ALL => 'Albania, Leke', | ||
| 84 | AMD => 'Armenia, Drams', | ||
| 85 | ANG => 'Netherlands Antilles, Guilders (also called Florins)', | ||
| 86 | AOA => 'Angola, Kwanza', | ||
| 87 | ARS => 'Argentina, Pesos', | ||
| 88 | AUD => 'Australia, Dollars', | ||
| 89 | AWG => 'Aruba, Guilders (also called Florins)', | ||
| 90 | AZM => 'Azerbaijan, Manats', | ||
| 91 | BAM => 'Bosnia and Herzegovina, Convertible Marka', | ||
| 92 | BBD => 'Barbados, Dollars', | ||
| 93 | BDT => 'Bangladesh, Taka', | ||
| 94 | BGN => 'Bulgaria, Leva', | ||
| 95 | BHD => 'Bahrain, Dinars', | ||
| 96 | BIF => 'Burundi, Francs', | ||
| 97 | BMD => 'Bermuda, Dollars', | ||
| 98 | BND => 'Brunei Darussalam, Dollars', | ||
| 99 | BOB => 'Bolivia, Bolivianos', | ||
| 100 | BRL => 'Brazil, Brazil Real', | ||
| 101 | BSD => 'Bahamas, Dollars', | ||
| 102 | BTN => 'Bhutan, Ngultrum', | ||
| 103 | BWP => 'Botswana, Pulas', | ||
| 104 | BYR => 'Belarus, Rubles', | ||
| 105 | BZD => 'Belize, Dollars', | ||
| 106 | CAD => 'Canada, Dollars', | ||
| 107 | CDF => 'Congo/Kinshasa, Congolese Francs', | ||
| 108 | CHF => 'Switzerland, Francs', | ||
| 109 | CLP => 'Chile, Pesos', | ||
| 110 | CNY => 'China, Yuan Renminbi', | ||
| 111 | COP => 'Colombia, Pesos', | ||
| 112 | CRC => 'Costa Rica, Colones', | ||
| 113 | CSD => 'Serbia, Dinars', | ||
| 114 | CUP => 'Cuba, Pesos', | ||
| 115 | CVE => 'Cape Verde, Escudos', | ||
| 116 | CYP => 'Cyprus, Pounds', | ||
| 117 | CZK => 'Czech Republic, Koruny', | ||
| 118 | DJF => 'Djibouti, Francs', | ||
| 119 | DKK => 'Denmark, Kroner', | ||
| 120 | DOP => 'Dominican Republic, Pesos', | ||
| 121 | DZD => 'Algeria, Algeria Dinars', | ||
| 122 | EEK => 'Estonia, Krooni', | ||
| 123 | EGP => 'Egypt, Pounds', | ||
| 124 | ERN => 'Eritrea, Nakfa', | ||
| 125 | ETB => 'Ethiopia, Birr', | ||
| 126 | EUR => 'Euro Member Countries, Euro', | ||
| 127 | FJD => 'Fiji, Dollars', | ||
| 128 | FKP => 'Falkland Islands (Malvinas), Pounds', | ||
| 129 | GBP => 'United Kingdom, Pounds', | ||
| 130 | GEL => 'Georgia, Lari', | ||
| 131 | GGP => 'Guernsey, Pounds', | ||
| 132 | GHC => 'Ghana, Cedis', | ||
| 133 | GIP => 'Gibraltar, Pounds', | ||
| 134 | GMD => 'Gambia, Dalasi', | ||
| 135 | GNF => 'Guinea, Francs', | ||
| 136 | GTQ => 'Guatemala, Quetzales', | ||
| 137 | GYD => 'Guyana, Dollars', | ||
| 138 | HKD => 'Hong Kong, Dollars', | ||
| 139 | HNL => 'Honduras, Lempiras', | ||
| 140 | HRK => 'Croatia, Kuna', | ||
| 141 | HTG => 'Haiti, Gourdes', | ||
| 142 | HUF => 'Hungary, Forint', | ||
| 143 | IDR => 'Indonesia, Rupiahs', | ||
| 144 | ILS => 'Israel, New Shekels', | ||
| 145 | IMP => 'Isle of Man, Pounds', | ||
| 146 | INR => 'India, Rupees', | ||
| 147 | IQD => 'Iraq, Dinars', | ||
| 148 | IRR => 'Iran, Rials', | ||
| 149 | ISK => 'Iceland, Kronur', | ||
| 150 | JEP => 'Jersey, Pounds', | ||
| 151 | JMD => 'Jamaica, Dollars', | ||
| 152 | JOD => 'Jordan, Dinars', | ||
| 153 | JPY => 'Japan, Yen', | ||
| 154 | KES => 'Kenya, Shillings', | ||
| 155 | KGS => 'Kyrgyzstan, Soms', | ||
| 156 | KHR => 'Cambodia, Riels', | ||
| 157 | KMF => 'Comoros, Francs', | ||
| 158 | KPW => 'Korea (North), Won', | ||
| 159 | KRW => 'Korea (South), Won', | ||
| 160 | KWD => 'Kuwait, Dinars', | ||
| 161 | KYD => 'Cayman Islands, Dollars', | ||
| 162 | KZT => 'Kazakhstan, Tenge', | ||
| 163 | LAK => 'Laos, Kips', | ||
| 164 | LBP => 'Lebanon, Pounds', | ||
| 165 | LKR => 'Sri Lanka, Rupees', | ||
| 166 | LRD => 'Liberia, Dollars', | ||
| 167 | LSL => 'Lesotho, Maloti', | ||
| 168 | LTL => 'Lithuania, Litai', | ||
| 169 | LVL => 'Latvia, Lati', | ||
| 170 | LYD => 'Libya, Dinars', | ||
| 171 | MAD => 'Morocco, Dirhams', | ||
| 172 | MDL => 'Moldova, Lei', | ||
| 173 | MGA => 'Madagascar, Ariary', | ||
| 174 | MKD => 'Macedonia, Denars', | ||
| 175 | MMK => 'Myanmar (Burma), Kyats', | ||
| 176 | MNT => 'Mongolia, Tugriks', | ||
| 177 | MOP => 'Macau, Patacas', | ||
| 178 | MRO => 'Mauritania, Ouguiyas', | ||
| 179 | MTL => 'Malta, Liri', | ||
| 180 | MUR => 'Mauritius, Rupees', | ||
| 181 | MVR => 'Maldives (Maldive Islands), Rufiyaa', | ||
| 182 | MWK => 'Malawi, Kwachas', | ||
| 183 | MXN => 'Mexico, Pesos', | ||
| 184 | MYR => 'Malaysia, Ringgits', | ||
| 185 | MZM => 'Mozambique, Meticais', | ||
| 186 | NAD => 'Namibia, Dollars', | ||
| 187 | NGN => 'Nigeria, Nairas', | ||
| 188 | NIO => 'Nicaragua, Cordobas', | ||
| 189 | NOK => 'Norway, Krone', | ||
| 190 | NPR => 'Nepal, Nepal Rupees', | ||
| 191 | NZD => 'New Zealand, Dollars', | ||
| 192 | OMR => 'Oman, Rials', | ||
| 193 | PAB => 'Panama, Balboa', | ||
| 194 | PEN => 'Peru, Nuevos Soles', | ||
| 195 | PGK => 'Papua New Guinea, Kina', | ||
| 196 | PHP => 'Philippines, Pesos', | ||
| 197 | PKR => 'Pakistan, Rupees', | ||
| 198 | PLN => 'Poland, Zlotych', | ||
| 199 | PYG => 'Paraguay, Guarani', | ||
| 200 | QAR => 'Qatar, Rials', | ||
| 201 | ROL => 'Romania, Lei', | ||
| 202 | RUB => 'Russia, Rubles', | ||
| 203 | RWF => 'Rwanda, Rwanda Francs', | ||
| 204 | SAR => 'Saudi Arabia, Riyals', | ||
| 205 | SBD => 'Solomon Islands, Dollars', | ||
| 206 | SCR => 'Seychelles, Rupees', | ||
| 207 | SDD => 'Sudan, Dinars', | ||
| 208 | SEK => 'Sweden, Kronor', | ||
| 209 | SGD => 'Singapore, Dollars', | ||
| 210 | SHP => 'Saint Helena, Pounds', | ||
| 211 | SIT => 'Slovenia, Tolars', | ||
| 212 | SKK => 'Slovakia, Koruny', | ||
| 213 | SLL => 'Sierra Leone, Leones', | ||
| 214 | SOS => 'Somalia, Shillings', | ||
| 215 | SPL => 'Seborga, Luigini', | ||
| 216 | SRD => 'Suriname, Dollars', | ||
| 217 | STD => 'São Tome and Principe, Dobras', | ||
| 218 | SVC => 'El Salvador, Colones', | ||
| 219 | SYP => 'Syria, Pounds', | ||
| 220 | SZL => 'Swaziland, Emalangeni', | ||
| 221 | THB => 'Thailand, Baht', | ||
| 222 | TJS => 'Tajikistan, Somoni', | ||
| 223 | TMM => 'Turkmenistan, Manats', | ||
| 224 | TND => 'Tunisia, Dinars', | ||
| 225 | TOP => 'Tonga, Pa\'anga', | ||
| 226 | TRL => 'Turkey, Liras [being phased out]', | ||
| 227 | TRY => 'Turkey, New Lira', | ||
| 228 | TTD => 'Trinidad and Tobago, Dollars', | ||
| 229 | TVD => 'Tuvalu, Tuvalu Dollars', | ||
| 230 | TWD => 'Taiwan, New Dollars', | ||
| 231 | TZS => 'Tanzania, Shillings', | ||
| 232 | UAH => 'Ukraine, Hryvnia', | ||
| 233 | UGX => 'Uganda, Shillings', | ||
| 234 | USD => 'United States of America, Dollars', | ||
| 235 | UYU => 'Uruguay, Pesos', | ||
| 236 | UZS => 'Uzbekistan, Sums', | ||
| 237 | VEB => 'Venezuela, Bolivares', | ||
| 238 | VND => 'Viet Nam, Dong', | ||
| 239 | VUV => 'Vanuatu, Vatu', | ||
| 240 | WST => 'Samoa, Tala', | ||
| 241 | XAF => 'Communauté Financière Africaine BEAC, Francs', | ||
| 242 | XAG => 'Silver, Ounces', | ||
| 243 | XAU => 'Gold, Ounces', | ||
| 244 | XCD => 'East Caribbean Dollars', | ||
| 245 | XDR => 'International Monetary Fund (IMF) Special Drawing Rights', | ||
| 246 | XOF => 'Communauté Financière Africaine BCEAO, Francs', | ||
| 247 | XPD => 'Palladium Ounces', | ||
| 248 | XPF => 'Comptoirs Français du Pacifique Francs', | ||
| 249 | XPT => 'Platinum, Ounces', | ||
| 250 | YER => 'Yemen, Rials', | ||
| 251 | ZAR => 'South Africa, Rand', | ||
| 252 | ZMK => 'Zambia, Kwacha', | ||
| 253 | ZWD => 'Zimbabwe, Zimbabwe Dollars', | ||
| 254 | ); | ||
| 255 | |||
| 256 | |||
| 257 | =head2 $self->validate(); | ||
| 258 | |||
| 259 | Validates this object to avoid constructing objects which are | ||
| 260 | in an inconsistent state. | ||
| 261 | |||
| 262 | returns 1 if the object validates, 0 otherwise. | ||
| 263 | |||
| 264 | =cut | ||
| 265 | sub validate | ||
| 266 | { | ||
| 267 | my $self = shift; | ||
| 268 | my $res = eval { | ||
| 269 | $self->validate_connection_fee() & | ||
| 270 | $self->validate_first_increment() & | ||
| 271 | $self->validate_increment() & | ||
| 272 | $self->validate_currency() & | ||
| 273 | $self->validate_rate() & | ||
| 274 | $self->validate_provider() & | ||
| 275 | $self->validate_label() & | ||
| 276 | $self->validate_prefix() | ||
| 277 | }; | ||
| 278 | $@ and do { | ||
| 279 | print $@ . "\n\n"; | ||
| 280 | use Data::Dumper; | ||
| 281 | die Dumper ($self); | ||
| 282 | }; | ||
| 283 | |||
| 284 | return $res; | ||
| 285 | } | ||
| 286 | |||
| 287 | |||
| 288 | =head2 $self->validate_connection_fee(); | ||
| 289 | |||
| 290 | Validate this object's 'connection_fee' attribute. | ||
| 291 | |||
| 292 | returns 1 if the attribute validates, 0 otherwise. | ||
| 293 | |||
| 294 | =cut | ||
| 295 | sub validate_connection_fee | ||
| 296 | { | ||
| 297 | my $self = shift; | ||
| 298 | |||
| 299 | my $val = $self->connection_fee(); | ||
| 300 | |||
| 301 | defined $val or do { | ||
| 302 | die 'asterisk/lcr/rate/connection_fee/undefined'; | ||
| 303 | return 0; | ||
| 304 | }; | ||
| 305 | |||
| 306 | is_number ($val) or do { | ||
| 307 | die "asterisk/lcr/rate/connection_fee/not_a_number : $val"; | ||
| 308 | return 0; | ||
| 309 | }; | ||
| 310 | |||
| 311 | return 1; | ||
| 312 | } | ||
| 313 | |||
| 314 | |||
| 315 | =head2 $self->set_connection_fee ($fee); | ||
| 316 | |||
| 317 | Sets the current object's 'connection_fee' attribute. | ||
| 318 | |||
| 319 | =cut | ||
| 320 | sub set_connection_fee | ||
| 321 | { | ||
| 322 | my $self = shift; | ||
| 323 | $self->{connection_fee} = shift; | ||
| 324 | } | ||
| 325 | |||
| 326 | |||
| 327 | =head2 $self->connection_fee(); | ||
| 328 | |||
| 329 | Returns the current object's 'connection_fee' attribute. | ||
| 330 | |||
| 331 | =cut | ||
| 332 | sub connection_fee | ||
| 333 | { | ||
| 334 | my $self = shift; | ||
| 335 | return $self->{connection_fee}; | ||
| 336 | } | ||
| 337 | |||
| 338 | |||
| 339 | =head2 $self->validate_first_increment(); | ||
| 340 | |||
| 341 | Validate this object's 'first_increment' attribute. | ||
| 342 | |||
| 343 | Returns 1 if the attribute validates, 0 otherwise. | ||
| 344 | |||
| 345 | =cut | ||
| 346 | sub validate_first_increment | ||
| 347 | { | ||
| 348 | my $self = shift; | ||
| 349 | |||
| 350 | my $val = $self->first_increment(); | ||
| 351 | |||
| 352 | defined $val or do { | ||
| 353 | die 'asterisk/lcr/rate/first_increment/undefined'; | ||
| 354 | return 0; | ||
| 355 | }; | ||
| 356 | |||
| 357 | is_number ($val) or do { | ||
| 358 | die 'asterisk/lcr/rate/first_increment/not_a_number'; | ||
| 359 | return 0; | ||
| 360 | }; | ||
| 361 | |||
| 362 | return 1; | ||
| 363 | } | ||
| 364 | |||
| 365 | |||
| 366 | =head2 $self->set_first_increment ($fee); | ||
| 367 | |||
| 368 | Sets the current object's 'first_increment' attribute. | ||
| 369 | |||
| 370 | =cut | ||
| 371 | sub set_first_increment | ||
| 372 | { | ||
| 373 | my $self = shift; | ||
| 374 | $self->{first_increment} = shift; | ||
| 375 | } | ||
| 376 | |||
| 377 | |||
| 378 | =head2 $self->first_increment(); | ||
| 379 | |||
| 380 | Returns the current object's 'first_increment' attribute. | ||
| 381 | |||
| 382 | =cut | ||
| 383 | sub first_increment | ||
| 384 | { | ||
| 385 | my $self = shift; | ||
| 386 | return $self->{first_increment}; | ||
| 387 | } | ||
| 388 | |||
| 389 | |||
| 390 | =head2 $self->validate_increment(); | ||
| 391 | |||
| 392 | Validate this object's 'increment' attribute. | ||
| 393 | |||
| 394 | Returns 1 if the attribute validates, 0 otherwise. | ||
| 395 | |||
| 396 | =cut | ||
| 397 | sub validate_increment | ||
| 398 | { | ||
| 399 | my $self = shift; | ||
| 400 | |||
| 401 | my $val = $self->increment(); | ||
| 402 | |||
| 403 | defined $val or do { | ||
| 404 | die 'asterisk/lcr/rate/increment/undefined'; | ||
| 405 | return 0; | ||
| 406 | }; | ||
| 407 | |||
| 408 | is_number ($val) or do { | ||
| 409 | die 'asterisk/lcr/rate/increment/not_a_number'; | ||
| 410 | return 0; | ||
| 411 | }; | ||
| 412 | |||
| 413 | return 1; | ||
| 414 | } | ||
| 415 | |||
| 416 | |||
| 417 | |||
| 418 | =head2 $self->set_increment ($fee); | ||
| 419 | |||
| 420 | Sets the current object's 'increment' attribute. | ||
| 421 | |||
| 422 | =cut | ||
| 423 | sub set_increment | ||
| 424 | { | ||
| 425 | my $self = shift; | ||
| 426 | $self->{increment} = shift; | ||
| 427 | } | ||
| 428 | |||
| 429 | |||
| 430 | =head2 $self->increment(); | ||
| 431 | |||
| 432 | Returns the current object's 'increment' attribute. | ||
| 433 | |||
| 434 | =cut | ||
| 435 | sub increment | ||
| 436 | { | ||
| 437 | my $self = shift; | ||
| 438 | return $self->{increment}; | ||
| 439 | } | ||
| 440 | |||
| 441 | |||
| 442 | =head2 $self->validate_rate(); | ||
| 443 | |||
| 444 | Validate this object's 'rate' attribute. | ||
| 445 | |||
| 446 | Returns 1 if the attribute validates, 0 otherwise. | ||
| 447 | |||
| 448 | =cut | ||
| 449 | sub validate_rate | ||
| 450 | { | ||
| 451 | my $self = shift; | ||
| 452 | |||
| 453 | my $val = $self->rate(); | ||
| 454 | |||
| 455 | defined $val or do { | ||
| 456 | die 'asterisk/lcr/rate/rate/undefined'; | ||
| 457 | return 0; | ||
| 458 | }; | ||
| 459 | |||
| 460 | is_number ($val) or do { | ||
| 461 | die 'asterisk/lcr/rate/rate/not_a_number'; | ||
| 462 | return 0; | ||
| 463 | }; | ||
| 464 | |||
| 465 | return 1; | ||
| 466 | } | ||
| 467 | |||
| 468 | |||
| 469 | =head2 $self->set_rate ($fee); | ||
| 470 | |||
| 471 | Sets the current object's 'rate' attribute. | ||
| 472 | |||
| 473 | =cut | ||
| 474 | sub set_rate | ||
| 475 | { | ||
| 476 | my $self = shift; | ||
| 477 | $self->{rate} = shift; | ||
| 478 | } | ||
| 479 | |||
| 480 | |||
| 481 | =head2 $self->rate(); | ||
| 482 | |||
| 483 | Returns the current object's 'rate' attribute. | ||
| 484 | |||
| 485 | =cut | ||
| 486 | sub rate | ||
| 487 | { | ||
| 488 | my $self = shift; | ||
| 489 | return $self->{rate}; | ||
| 490 | } | ||
| 491 | |||
| 492 | |||
| 493 | =head2 $self->validate_currency(); | ||
| 494 | |||
| 495 | Validate this object's 'currency' attribute. | ||
| 496 | |||
| 497 | Returns 1 if the attribute validates, 0 otherwise. | ||
| 498 | |||
| 499 | =cut | ||
| 500 | sub validate_currency | ||
| 501 | { | ||
| 502 | my $self = shift; | ||
| 503 | |||
| 504 | my $val = $self->currency(); | ||
| 505 | |||
| 506 | defined $val or do { | ||
| 507 | die 'asterisk/lcr/rate/currency/undefined'; | ||
| 508 | return 0; | ||
| 509 | }; | ||
| 510 | |||
| 511 | $CURRENCY{$val} or do { | ||
| 512 | die 'asterisk/lcr/rate/currency/unknown'; | ||
| 513 | return 0; | ||
| 514 | }; | ||
| 515 | |||
| 516 | return 1; | ||
| 517 | } | ||
| 518 | |||
| 519 | |||
| 520 | =head2 $self->set_currency ($fee); | ||
| 521 | |||
| 522 | Sets the current object's 'currency' attribute. | ||
| 523 | |||
| 524 | =cut | ||
| 525 | sub set_currency | ||
| 526 | { | ||
| 527 | my $self = shift; | ||
| 528 | $self->{currency} = shift; | ||
| 529 | } | ||
| 530 | |||
| 531 | |||
| 532 | =head2 $self->currency(); | ||
| 533 | |||
| 534 | Returns the current object's 'currency' attribute. | ||
| 535 | |||
| 536 | =cut | ||
| 537 | sub currency | ||
| 538 | { | ||
| 539 | my $self = shift; | ||
| 540 | return $self->{currency}; | ||
| 541 | } | ||
| 542 | |||
| 543 | |||
| 544 | =head2 $self->validate_provider(); | ||
| 545 | |||
| 546 | Validate this object's 'provider' attribute. | ||
| 547 | |||
| 548 | Returns 1 if the attribute validates, 0 otherwise. | ||
| 549 | |||
| 550 | =cut | ||
| 551 | sub validate_provider | ||
| 552 | { | ||
| 553 | my $self = shift; | ||
| 554 | |||
| 555 | my $val = $self->provider(); | ||
| 556 | |||
| 557 | defined $val or do { | ||
| 558 | die 'asterisk/lcr/rate/provider/undefined'; | ||
| 559 | return 0; | ||
| 560 | }; | ||
| 561 | |||
| 562 | return 1; | ||
| 563 | } | ||
| 564 | |||
| 565 | |||
| 566 | =head2 $self->set_provider ($fee); | ||
| 567 | |||
| 568 | Sets the current object's 'provider' attribute. | ||
| 569 | |||
| 570 | =cut | ||
| 571 | sub set_provider | ||
| 572 | { | ||
| 573 | my $self = shift; | ||
| 574 | $self->{provider} = shift; | ||
| 575 | } | ||
| 576 | |||
| 577 | |||
| 578 | =head2 $self->provider(); | ||
| 579 | |||
| 580 | Returns the current object's 'provider' attribute. | ||
| 581 | |||
| 582 | =cut | ||
| 583 | sub provider | ||
| 584 | { | ||
| 585 | my $self = shift; | ||
| 586 | return $self->{provider}; | ||
| 587 | } | ||
| 588 | |||
| 589 | |||
| 590 | =head2 $self->validate_label(); | ||
| 591 | |||
| 592 | Validate this object's 'label' attribute. | ||
| 593 | |||
| 594 | Returns 1 if the attribute validates, 0 otherwise. | ||
| 595 | |||
| 596 | =cut | ||
| 597 | sub validate_label | ||
| 598 | { | ||
| 599 | my $self = shift; | ||
| 600 | |||
| 601 | my $val = $self->label(); | ||
| 602 | |||
| 603 | defined $val or do { | ||
| 604 | die 'asterisk/lcr/rate/label/undefined'; | ||
| 605 | return 0; | ||
| 606 | }; | ||
| 607 | |||
| 608 | return 1; | ||
| 609 | } | ||
| 610 | |||
| 611 | |||
| 612 | =head2 $self->set_label ($fee); | ||
| 613 | |||
| 614 | Sets the current object's 'label' attribute. | ||
| 615 | |||
| 616 | =cut | ||
| 617 | sub set_label | ||
| 618 | { | ||
| 619 | my $self = shift; | ||
| 620 | $self->{label} = shift; | ||
| 621 | } | ||
| 622 | |||
| 623 | |||
| 624 | =head2 $self->label(); | ||
| 625 | |||
| 626 | Returns the current object's 'label' attribute. | ||
| 627 | |||
| 628 | =cut | ||
| 629 | |||
| 630 | sub label | ||
| 631 | { | ||
| 632 | my $self = shift; | ||
| 633 | return $self->{label} || '?'; | ||
| 634 | } | ||
| 635 | |||
| 636 | |||
| 637 | =head2 $self->validate_prefix(); | ||
| 638 | |||
| 639 | Validate this object's 'prefix' attribute. | ||
| 640 | |||
| 641 | Returns 1 if the attribute validates, 0 otherwise. | ||
| 642 | |||
| 643 | =cut | ||
| 644 | sub validate_prefix | ||
| 645 | { | ||
| 646 | my $self = shift; | ||
| 647 | |||
| 648 | my $val = $self->prefix(); | ||
| 649 | |||
| 650 | defined $val or do { | ||
| 651 | die 'asterisk/lcr/rate/prefix/undefined'; | ||
| 652 | return 0; | ||
| 653 | }; | ||
| 654 | |||
| 655 | return 1; | ||
| 656 | } | ||
| 657 | |||
| 658 | |||
| 659 | =head2 $self->set_prefix ($fee); | ||
| 660 | |||
| 661 | Sets the current object's 'prefix' attribute. | ||
| 662 | |||
| 663 | =cut | ||
| 664 | sub set_prefix | ||
| 665 | { | ||
| 666 | my $self = shift; | ||
| 667 | $self->{prefix} = shift; | ||
| 668 | } | ||
| 669 | |||
| 670 | |||
| 671 | =head2 $self->prefix(); | ||
| 672 | |||
| 673 | Returns the current object's 'prefix' attribute. | ||
| 674 | |||
| 675 | =cut | ||
| 676 | sub prefix | ||
| 677 | { | ||
| 678 | my $self = shift; | ||
| 679 | return $self->{prefix}; | ||
| 680 | } | ||
| 681 | |||
| 682 | |||
| 683 | sub is_number | ||
| 684 | { | ||
| 685 | local ($_) = shift; | ||
| 686 | if (/^\d+$/) { return 1 } | ||
| 687 | if (/^-?\d+$/) { return 1 } | ||
| 688 | if (/^[+-]?\d+$/) { return 1 } | ||
| 689 | if (/^-?\d+\.?\d*$/) { return 1 } | ||
| 690 | if (/^-?(?:\d+(?:\.\d*)?|\.\d+)$/) { return 1 } | ||
| 691 | if (/^([+-]?)(?=\d|\.\d)\d*(\.\d*)?([Ee]([+-]?\d+))?$/) { return 1 } | ||
| 692 | return; | ||
| 693 | } | ||
| 694 | |||
| 695 | |||
| 696 | 1; | ||
| 697 | |||
| 698 | |||
| 699 | __END__ |