# Copyright (c) 2006-2007 bivio Software, Inc. All Rights Reserved. # # Visit http://www.bivio.biz for more info. # # This library is free software; you can redistribute it and/or modify # it under the terms of the GNU Lesser General Public License as # published by the Free Software Foundation; either version 2.1 of the # License, or (at your option) any later version. # # This library is distributed in the hope that it will be useful, but # WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # Lesser General Public License for more details. # # You should have received a copy of the GNU Lesser General Public # License along with this library; If not, you may get a copy from: # http://www.opensource.org/licenses/lgpl-license.html # # $Id: BlogFileName.pm,v 1.9 2010/12/03 17:44:06 nagler Exp $ package Bivio::Type::BlogFileName; use strict; use Bivio::Base 'Type.DocletFileName'; our($VERSION) = sprintf('%d.%02d', q$Revision: 1.9 $ =~ /\d+/g); my($_DT) = Bivio::Type->get_instance('DateTime'); sub ERROR { return Bivio::TypeError->BLOG_FILE_NAME; } sub PRIVATE_FOLDER { return shift->BLOG_FOLDER; } sub PATH_REGEX { return qr{@{[shift->join('(\d{6})', '(\d{8})')]}}o; } sub REGEX { return qr{(\d{14})}; } sub SQL_LIKE_BASE { my($proto) = @_; return _base($proto, '_' x $proto->get_width); } sub from_date_time { my(undef, $date_time) = @_; return $_DT->to_file_name($date_time); } sub from_literal_stripper { my(undef, $v) = @_; # This is overly friendly, but we are parsing pretty much anything following # the name. $v =~ s{\D}{}g; $v = substr($v, 0, 14); return $v; } sub from_sql_column { my($proto, $value) = @_; return $proto->is_absolute($value) ? $proto->from_absolute($value) : $proto->from_literal_or_die($value); } sub get_width { return 14; } sub to_absolute { my($proto, $value) = (shift, shift); return $proto->SUPER::to_absolute( !$value ? '' : $proto->SQL_LIKE_BASE eq $value ? $value : _base($proto, $value), @_, ); } sub to_sql_param { return _base(@_); } sub _base { my($proto, $value) = @_; Bivio::Die->die($value, ': invalid value') unless $value =~ /^([\d_]{6})([\d_]{8})$/; return $proto->join($1, $2); } 1;