| 1 | package IPIP; | ||
| 2 | |||
| 3 | use 5.010001; | ||
| 4 | use strict; | ||
| 5 | use warnings; | ||
| 6 | use Carp; | ||
| 7 | use POSIX (); | ||
| 8 | use POSIX qw(setsid); | ||
| 9 | use POSIX qw(:errno_h :fcntl_h); | ||
| 10 | |||
| 11 | require Exporter; | ||
| 12 | |||
| 13 | our @ISA = qw(Exporter); | ||
| 14 | |||
| 15 | # Items to export into callers namespace by default. Note: do not export | ||
| 16 | # names by default without a very good reason. Use EXPORT_OK instead. | ||
| 17 | # Do not simply export all your public functions/methods/constants. | ||
| 18 | |||
| 19 | # This allows declaration use IPIP ':all'; | ||
| 20 | # If you do not need this, moving things directly into @EXPORT or @EXPORT_OK | ||
| 21 | # will save memory. | ||
| 22 | our %EXPORT_TAGS = ( 'all' => [ qw( | ||
| 23 | |||
| 24 | ) ] ); | ||
| 25 | |||
| 26 | our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } ); | ||
| 27 | |||
| 28 | our @EXPORT = qw( | ||
| 29 | |||
| 30 | ); | ||
| 31 | |||
| 32 | our $VERSION = '0.01'; | ||
| 33 | |||
| 34 | require XSLoader; | ||
| 35 | XSLoader::load('IPIP', $VERSION); | ||
| 36 | |||
| 37 | # Preloaded methods go here. | ||
| 38 | |||
| 39 | our $INSTANCE; | ||
| 40 | sub new { | ||
| 41 | my ($class, %connect_args) = @_; | ||
| 42 | unless ($INSTANCE) { | ||
| 43 | $INSTANCE = bless {}, __PACKAGE__; | ||
| 44 | $INSTANCE->{'inited'}=0; | ||
| 45 | $INSTANCE->{'last'}=0; | ||
| 46 | } | ||
| 47 | my $reason=$INSTANCE->init( | ||
| 48 | $connect_args{path_info} | ||
| 49 | ); | ||
| 50 | if($reason) | ||
| 51 | { | ||
| 52 | $INSTANCE->{'last'}=0; | ||
| 53 | warn "Could not init file because:".POSIX::strerror($reason); | ||
| 54 | if($INSTANCE->{'inited'}) | ||
| 55 | { | ||
| 56 | return $INSTANCE; | ||
| 57 | } | ||
| 58 | return undef; | ||
| 59 | } | ||
| 60 | $INSTANCE->{'last'}=1; | ||
| 61 | $INSTANCE->{'inited'}=1; | ||
| 62 | return $INSTANCE; | ||
| 63 | }; | ||
| 64 | sub check_last { | ||
| 65 | return $INSTANCE->{'last'}; | ||
| 66 | }; | ||
| 67 | 1; | ||
| 68 | __END__ |