Basset

 view release on metacpan or  search on metacpan

basset.conf  view on Meta::CPAN

# this is a sample conf file. By default, Basset::Object::Conf looks at confs file in
# /etc/basset.conf
# ./basset.conf
# Basset/Object/basset.conf
# lib/Basset/Object/basset.conf
# so you may place config files there, or edit Basset::Object::Conf to look elsewhere.

define package Basset::DB

#turn off transactions if you don't need 'em
-transactions 	= 1

lib/Basset/DB/Table.pm  view on Meta::CPAN

You should always use the quoted version unless you've received the numeric type from an authoritative
source, such as having it returned from the database as the column type.

Alternatively, if you don't want to use a definition, you can explicitly tell the constructor your non primary columns

 $table = Basset::DB::Table->new(
 	'primary_column' => 'id',
 	'non_primary_columns' => [qw(name age serial_number)],
 );

That takes the place of using the definition. It does a discover call behind the scenes, but only looks for the columns
that you've specified, not everything in the table.

=cut

=pod

=begin btest definition

my $o = __PACKAGE__->new();
$test->ok($o, "Got object");

lib/Basset/DB/Table.pm  view on Meta::CPAN

   'binds' => 0/1
  }
 }

"method" is obviously the name of the method that's being re-written.
"query_type" is the flag to indicate the type of query. "I" for insert, "U" for update, "D" for delete, "R" for replace,
or "A" for all.
"binds" is a boolean flag, 0 or 1. Set to 0 if you're inserting a new value that doesn't need a binded param, such as "NOW()".
Set it to 1 if you're inserting a new value that does need a binded param, such as "LCASE(?)" to insert the value in lower case.

And voila. When the query is constructed, internally it first looks for a re-write of the method for the given query type. If
it doesn't find one, it looks for a re-write of type "A" (all queries), if it doesn't find one of those, then it just leaves it
alone and preps the query to insert the value in as is, unchanged.

One useful example that I will include, is to make a column read-only:

 $table->db_write_translation(
 	{
 		$column => {
 			'U' => {
 				'val' => $column,
 				'binds' => 0

lib/Basset/Object.pm  view on Meta::CPAN

=item add_attr

add_attr adds object attributes to the class.

Okay, now we're going to get into some philosophy. First of all, let me state that I *love* Perl's OO implementation.
I usually get smacked upside the head when I say that, but I find it really easy to use, work with, manipulate, and so
on. And there are things that you can do in Perl's OO that you can't in Java or C++ or the like. Perl, for example, can
have *totally* private values that are completely inaccessible (lexicals, natch). private vars in the other languages
can be redefined or tweaked or subclassed or otherwise gotten around in some form. Not Perl.

And I obviously just adore Perl anyway. I get funny looks when I tell people that I like perl so much because it works
the way I think. That bothers people for some reason.

Anyway, as much as I like how it works, I don't like the fact that there's no consistent object type. An object is,
of course, a blessed ((thingie)) (scalar, array, code, hash, etc) reference. And there are merits to using any of those
things, depending upon the situation. Hashes are easy to work with and most similar to traditional objects.

 $object->{$attribute} = $value;

And whatnot. Arrays are much faster (typically 33% in tests I've done), but they suck to work with.

lib/Basset/Object.pm  view on Meta::CPAN

		return $parent unless $parent->restricted();
	};

	return $self->error("class ($self) has no non-restricted parents", "BO-18");
}

=pod

=item dump

->dump dumps out the object (using Data::Dumper internally), this is useful to show you what an object looks like.

 print $obj->dump

Alternatively, you can hand in something to dump.

 print $obj->dump($something_else);

=cut

=pod

lib/Basset/Object.pm  view on Meta::CPAN


 __PACKAGE__->errortranslator(
	{
		'violation of key constraint foo: Cannot INSERT' => 'Please specify a value for foo'
	}
 );

 $obj->do_something || die $obj->error(); 	# dies 'violation of key constraint foo: Cannot INSERT'
 $obj->do_something || die $obj->usererror();# dies 'Please specify a value for foo'

The error translator looks at the error values, and if a more friendly user error exists, it returns that one instead.
errortranslator looks at and returns (in order):

 the actual error,
 the raw error, 
 the error code, 
 a '*' wildcard, 
 and then just returns the original error w/o modification.

Be careful using the '*' wildcard. This will translate -any- error message that doesn't have a friendlier version.

=cut

lib/Basset/Object/Persistent.pm  view on Meta::CPAN


This is exactly equivalent to:

 my $users = Some::Class->load_all(
 	{
 		'where' => 'user = ? and location = ? and weather = ?'
 	},
 	3, 'mountains', 'sunny'
 );

It just looks prettier and hides more of the SQL.

Even better, you can also stick in an array for multiple value loads.

 my $users = Some::Class->load_where(
 	'state'		=> 'PA',
 	'last_name' => [qw(Smith Jones Johnson)]
 );

Is exactly the same as:

lib/Basset/Template.pm  view on Meta::CPAN


Boolean flag. 1/0.

templates are obviously not executable code. Nothing can be done with them, they're nonsensical. So, before they can
be used, they must be preprocessed into something useful. That preprocessing step is reasonably fast, but it's still
effectively overhead. You don't care about the transformations happening, you just want it to work!

Besides most templates are modified very rarely - it's normally the same thing being re-displayed. So constantly re-preprocessing
it is inefficient. So, you may turn on caching.

If caching is on, during preprocessing the template looks in your cache_dir. If it finds a preprocessed version that is
current, it grabs that version and returns it. No more additional processing. If it finds a preprocessed version that is
out of date (i.e., the actual template was modified after the cached version was created) then it looks to the new
template and re-caches it. If no cached value is found, then one is cached for future use.

=cut

__PACKAGE__->add_attr('caching');

=pod

=item cache_dir



( run in 0.496 second using v1.01-cache-2.11-cpan-607d282f910 )