|
|
| |
T2::Class(3) |
User Contributed Perl Documentation |
T2::Class(3) |
T2::Class - Classes in a T2 schema
my $class = T2::Class->new
( name => "My::Package",
table => "db_table", # optional
attributes => [ ... ],
associations => [ ... ],
methods => [ ... ] );
A T2::Class is a class in a Tangram schema.
Returns the Tangram::Schema fragment that corresponds to this class.
- $class->attributes
- In list context, returns all of the attributes (NOT associations) that
this class has, including attributes defined in parent classes. The
ordering of the returned attributes is stable.
In scalar context, return a Set::Object which is the list of
attributes that belong to this class only.
- $class->associations
- In list context, returns all of the associations this class has,
including associations defined in parent classes. The ordering of
the returned associations is stable.
It will also include associations that are not from
this class but to this class, but only if the association has a
name defined for the back-reference. The association is in this case a
mirror of the association for the original reference. Such associations
are detectable, because they return 1 to
$association->is_backwards();
In scalar context, return a Set::Object which is the list of
associations that belong to this class only, and without the
backwards associations.
- $class->rev_assocs
- In list context, returns all of the associations that refer to this
class, including associations defined in parent classes.
It will also include associations that are not
to this class but from this class, but only if they have
both names (source and destination) defined. The association is in this
case a mirror of the association for the original reference. Such
associations are detectable, because they return 1 to
$association->is_backwards();
In scalar context, return an ARRAY ref which is the list of
associations that belong to this class only, and without the
backwards associations.
- $class->methods
- In list context, this method returns all of the methods that this class
has defined as T2::Method objects, including inherited
methods. In some cases this may mean you get a method twice, if it
is over-ridden by a sub-class.
In scalar context, returns a Set::Object with all of the
methods in it, for only this class.
- $class->all_methods
- The all_methods function augments the list returned by the
"methods" function by including accessor
methods that the attributes and associations defined by the class would
include.
This assumes that you are generating your classes using the
included class generator, and using them with Class::Tangram 1.50+.
- $class->get_method("name")
- Returns the method named by "name" for this class.
If defined in more than one superclass, returns the most
specific version.
- $class->method(...)
- If given a T2::Method object, then it adds that method to this Class'
list.
If given the name of a method, returns the method that matches
that name.
- $class->get_attribute($name)
- $class->attribute(...)
- get_attribute(), or attribute() with only the name of an
attribute return the T2::Attribute object that is the attribute.
attribute() can also be used to add attributes to the
class, if passed an Attribute object.
- $class->get_association($name)
- $class->association(...)
- get_association(), or association() with only the name of an
association return the T2::Association object that is the association.
association() can also be used to add associations to
the class, if passed an Association object.
- $class->cancan("method")
- Returns the T2::Method object that implements the passed method, or undef.
This will never return an accessor, unlike
"$class->get_method("method")".
- $class->on_disk()
- Returns the path to the .pm that corresponds to this path, if found in
@INC.
- $class->is_uptodate([ $filename ])
- Returns true if the version of the class on the disk is newer than the
newest of the class, and all of its attributes, associations and
methods.
- $class->is_a($what)
- Identical to the Perl UNIVERSAL::isa method, but works on the Schema
structure rather than the compiled @SomeClass::ISA
variables.
- $class->compare($class2)
- Returns 0 if the classes are the same, or are unrelated.
Returns 1 if $class2 is a
descendant of $class
Returns 2 if $class2 is a
superclass of $class
What this means is if you use code like this:
my @classes = sort $schema->classes;
eval ("use $_;") foreach @classes;
You're guaranteed not to have any inheritance dependancy
problems.
- set_from_fields($fields)
- Sets up fields in a T2::Class object, gleaning information from
$fields, which you perhaps found in
$YourClass::fields, or perhaps a section of an
existing Tangram 2 schema.
Note that it is not possible to set up association objects
correctly until all associations are present in the schema. This will
automatically happen when you insert Classes into the schema.
Traverses over every object in the class, setting $_[0]
to the item.
Hey! The above document had some coding errors, which are explained
below:
- Around line 197:
- '=item' outside of any '=over'
- Around line 788:
- You forgot a '=back' before '=head2'
- Around line 814:
- =back without =over
Visit the GSP FreeBSD Man Page Interface. Output converted with ManDoc. |