PROXY  WHOIS  RQUOTE  TEXTS  SOFT  FOREX  BBOARD
 Music  Philosophy  Code  Literature  Russian

= ROOT|Technical|Code_Examples|Perl|site_perl|HTML|Element.pm =

page 7 of 39




sub all_attr_names {
    return keys %{$_[0]};
}


=head2 $h->all_external_attr()

Like C<all_attr>, except that internal attributes are not present.

=head2 $h->all_external_attr_names()

Like C<all_external_attr_names>, except that internal attributes' names
are not present.

=cut

sub all_external_attr {
  my $self = $_[0];
  return
    map(
        (length($_) && substr($_,0,1) eq '_') ? () : ($_, $self->{$_}),
        keys %$self
       );
}

sub all_external_attr_names {
  return
    grep
      !(length($_) && substr($_,0,1) eq '_'),
      keys %{$_[0]}
  ;
}



=head2 $h->id() or $h->id($string)

Returns (optionally sets to C<$string>) the "id" attribute.
C<< $h->id(undef) >> deletes the "id" attribute.

=cut

sub id {
  if(@_ == 1) {
    return $_[0]{'id'};
  } elsif(@_ == 2) {
    if(defined $_[1]) {
      return $_[0]{'id'} = $_[1];
    } else {
      return delete $_[0]{'id'};
    }
  } else {
    Carp::croak '$node->id can\'t take ' . scalar(@_) . ' parameters!';
  }
}


=head2 $h->idf() or $h->idf($string)

Just like the C<id> method, except that if you call C<< $h->idf() >> and
no "id" attribute is defined for this element, then it's set to a
likely-to-be-unique value, and returned.  (The "f" is for "force".)

=cut

sub _gensym {
  unless(defined $ID_COUNTER) {
    # start it out...
    $ID_COUNTER = sprintf('%04x', rand(0x1000));
    $ID_COUNTER =~ tr<0-9a-f><J-NP-Z>; # yes, skip letter "oh"
    $ID_COUNTER .= '00000';
  }
  ++$ID_COUNTER;
}

sub idf {
    my $nparms = scalar @_;

    if ($nparms == 1) {
        my $x;
        if (defined($x = $_[0]{'id'}) and length $x) {
            return $x;
        }
        else {
            return $_[0]{'id'} = _gensym();
        }
    }
    if ($nparms == 2) {
        if (defined $_[1]) {
            return $_[0]{'id'} = $_[1];
        }
        else {
            return delete $_[0]{'id'};
        }
    }
    Carp::croak '$node->idf can\'t take ' . scalar(@_) . ' parameters!';
}


=7=

1|2|3|4|5|6| < PREV = PAGE 7 = NEXT > |8|9|10|11|12|13|14|15|16.39

UP TO ROOT | UP TO DIR | TO FIRST PAGE

Google
 


E-mail Facebook Google Digg del.icio.us BlinkList Fark Furl Ma.gnolia Netscape NewsVine Reddit Slashdot Spurl StumbleUpon Technorati YahooMyWeb LiveJournal Blogmarks TwitThis Live News2.ru BobrDobr.ru Memori.ru MoeMesto.ru

0.00693202 wallclock secs ( 0.01 usr + 0.00 sys = 0.01 CPU)